Publish messages to an Amazon SNS topic with Step Functions
Learn how to use Step Functions to publish messages to an Amazon SNS topic. This page lists the supported Amazon SNS API actions and
provides example Task
states to publish message to Amazon SNS.
To learn about integrating with Amazon services in Step Functions, see Integrating services and Passing parameters to a service API in Step Functions.
Key features of Optimized Amazon SNS integration
There are no optimizations for the Request Response or Wait for a Callback with Task Token integration patterns.
The following includes a Task
state that publishes to an Amazon Simple Notification Service (Amazon SNS)
topic.
{
"StartAt": "Publish to SNS",
"States": {
"Publish to SNS": {
"Type": "Task",
"Resource": "arn:aws-cn:states:::sns:publish",
"Parameters": {
"TopicArn": "arn:aws-cn:sns:us-east-1:123456789012:myTopic",
"Message.$": "$.input.message",
"MessageAttributes": {
"my_attribute_no_1": {
"DataType": "String",
"StringValue": "value of my_attribute_no_1"
},
"my_attribute_no_2": {
"DataType": "String",
"StringValue": "value of my_attribute_no_2"
}
}
},
"End": true
}
}
}
Passing dynamic values. You can modify the above example to dynamically pass an attribute from this JSON payload:
{ "input": { "message": "Hello world" }, "SNSDetails": { "attribute1": "some value", "attribute2": "some other value", } }
Append the .$
to the StringValue
field:
"MessageAttributes": { "my_attribute_no_1": { "DataType": "String", "StringValue.$": "$.SNSDetails.attribute1" }, "my_attribute_no_2": { "DataType": "String", "StringValue.$": "$.SNSDetails.attribute2" }
The following includes a Task
state that publishes to an Amazon SNS topic, and
then waits for the task token to be returned. See Wait for a Callback with Task Token.
{
"StartAt":"Send message to SNS",
"States":{
"Send message to SNS":{
"Type":"Task",
"Resource":"arn:aws:states:::sns:publish.waitForTaskToken",
"Parameters":{
"TopicArn":"arn:aws:sns:us-east-1:123456789012:myTopic",
"Message":{
"Input.$":"$",
"TaskToken.$":"$$.Task.Token"
}
},
"End":true
}
}
}
Supported Amazon SNS APIs
-
-
Supported Parameters
Parameters in Step Functions are expressed in PascalCase
Even if the native service API is in camelCase, for example the API action startSyncExecution
, you specify parameters in PascalCase, such as: StateMachineArn
.
Note
There is a quota for the maximum input or result data size for a task in Step Functions. This restricts you to 256 KiB of data as a UTF-8 encoded string when you send to, or receive data from, another service. See Quotas related to state machine executions.
IAM policies for calling Amazon SNS
The following example templates show how Amazon Step Functions generates IAM policies based on the resources in your state machine definition. For more information, see How Step Functions generates IAM policies for integrated services and Discover service integration patterns in Step Functions.
Static resources
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": [
"arn:aws:sns:[[region]]
:[[accountId]]
:[[topicName]]
"
]
}
]
}
Resources based on a Path, or publishing to TargetArn
or
PhoneNumber
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": "*"
}
]
}