Publish to AWS SNS topic(s) about events. Create a publisher with (sns-publisher opts), then create streams which publish to topic(s) with (your-publisher “your::arn”). Or simply call sns-publish or sns-publish-async directly.







(sns-publish aws-opts msg-opts events)

Synchronously publish an event, or a sequence of events, with the given aws and msg options.


(sns-publish-async aws-opts msg-opts events & [async-opts])

Asynchronously publish an event, or a sequence of events, with the given aws, msg and async options.


(sns-publisher)(sns-publisher opts)(sns-publisher aws-opts msg-opts & [async-opts])

Returns a publisher, which is a function invoked with a topic ARN or a sequence of ARNs and returns a stream. That stream is a function which takes a single event, or a sequence of events, and publishes a message about them.

(def sns (sns-publisher))

(changed :state
  (sns "arn:aws:sns:region:id:xerxes" "arn:aws:sns:region:id:shodan"))

The first argument is a map of AWS credentials:

  • :access-key ; required
  • :secret-key ; required
  • :region ; optional

The :region value is passed to com.amazonaws.regions.RegionUtils/getRegion. For a list of region names that you can use, see: https://github.com/aws/aws-sdk-java/blob/master/src/main/java/com/amazonaws/regions/Regions.java

(Note: getRegion expects the value of the name instance variable, not the enum type name.)

The second argument is a map of default message options, like :body or :subject.

(def sns (sns-publisher {:access-key "my-access-key"
                         :secret-key "my-secret-key"}
                        {:subject "something is ok"}))

The third is an optional map specifying async options:

  • :async ; optional true / false (default)
  • :success ; optional callback invoked on success ; e.g. (fn req res …)
  • :error ; optional callback invoked on error ; e.g. (fn exception …) ; you must specify both :success and :error ; or else, none at all

If you provide a single map, they will be split out for you.

(def sns (sns-publisher {:access-key "your-access-key"
                         :secret-key "your-secret-key"
                         :subject "something went wrong"
                         :async true}))

By default, riemann uses (riemann.common/subject events) and (riemann.common/body events) to format messages. You can set your own subject or body formatter functions by including :subject or :body in msg-opts. These formatting functions take a sequence of events and return a string.

(def sns (sns-publisher {} {:body (fn [events]
                                    (apply prn-str events))}))