In the following example we create a new SNS topic with the name dispatch
which is bound to the dispatcher
function. The function will be called every time a message is sent to the dispatch
topic.
functions:
dispatcher:
handler: dispatcher.dispatch
events:
- sns: dispatch
You're also able to add the same SNS topic to multiple functions:
functions:
dispatcher:
handler: dispatcher.dispatch
events:
- sns: dispatch
dispatcher2:
handler: dispatcher2.dispatch
events:
- sns: dispatch
This will run both functions for a message sent to the dispatch topic.
If an arn:
is specified, the framework will give permission to the topic to invoke the function and subscribe the function to the topic.
functions:
dispatcher:
handler: dispatcher.dispatch
events:
- sns: arn:xxx
functions:
dispatcher:
handler: dispatcher.dispatch
events:
- sns:
arn: arn:xxx
Or with intrinsic CloudFormation function like Fn::Join
or Fn::GetAtt
.
functions:
dispatcher:
handler: dispatcher.dispatch
events:
- sns:
arn:
Fn::Join:
- ""
- - "arn:aws:sns:"
- Ref: "AWS::Region"
- ":"
- Ref: "AWS::AccountId"
- ":MyCustomTopic"
topicName: MyCustomTopic
Note: It is important to know that topicArn
must contain the value given in the topicName
property.
This event definition ensures that the aggregator
function gets called every time a message is sent to the
aggregate
topic. Data aggregation pipeline
will be shown in the AWS console so that the user can understand what the
SNS topic is used for.
functions:
aggregator:
handler: aggregator.handler
events:
- sns:
topicName: aggregate
displayName: Data aggregation pipeline
This event definition creates an SNS topic which subscription uses a filter policy. The filter policy filters out messages that don't have attribute key pet
with value dog
or cat
.
functions:
pets:
handler: pets.handler
events:
- sns:
topicName: pets
filterPolicy:
pet:
- dog
- cat
developers
Made with love in San Francisco + Atlanta, Austria, Germany, Pakistan, Poland, Nebraska & Thailand
Serverless, Inc. © 2018