Customise emitted SNS message in state machine
0
I have the following state machine step:
"Step Name": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn": "${TopicARN}",
"Message.$": "States.JsonToString($)",
"MessageAttributes": {
"type": {
"DataType": "String",
"StringValue": "$.type"
},
"id": {
"DataType": "String",
"StringValue": "$.id"
}
}
},
"End": true
}
which works fine but I'd like to customise the body of the SNS message, somehow like this:
"Step Name": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn": "${TopicARN}",
"Message.$": {
"id": "$.id",
"param1": "$.param1",
"param2": "$.param2",
"metadata": "$"
},
"MessageAttributes": {
"type": {
"DataType": "String",
"StringValue": "$.type"
},
"id": {
"DataType": "String",
"StringValue": "$.id"
}
}
},
"End": true
}
However it does not work because Message
has to be a String
. I was hoping to wrap my object in States.JsonToString
but that also doesn't seem to work.
Is there a way to achieve this or will I have to resort to using a lambda instead of the SNS integration?
asked 9 days ago4 views
1 Answers
1
Accepted Answer
To specify that a parameter use a path to reference a JSON node in the input, end the parameter name with .$ (from doc).
In your case:
"Step Name": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn": "${TopicARN}",
"Message": {
"id.$": "$.id",
"param1.$": "$.param1",
"param2.$": "$.param2",
"metadata.$": "$"
},
"MessageAttributes": {
"type": {
"DataType": "String",
"StringValue.$": "$.type"
},
"id": {
"DataType": "String",
"StringValue.$": "$.id"
}
}
},
"End": true
}
Relevant questions
How to set up IAM roles/policies to run Fargate tasks inside a step function?
asked 2 months agoFailed to convert 'Body' to string S3.InvalidContent arn:aws:states:::aws-sdk:s3:getObject step function
Accepted Answerasked 14 days agoCustomise emitted SNS message in state machine
Accepted Answerasked 9 days agoInvalid security token error when executing nested step function on Step Functions Local
asked 3 days agoPass parameters to next step function task
Accepted Answerasked a month agoCan I specify GET URL path parameter in step function?
asked 3 months agoPossible to have a single parameter receive its value conditionally?
asked 2 years agoStep function state to execute a Glue job seems to be stalling
asked a year agoHow do I use JSON Lambda output in Step Functions
Accepted AnswerAWS: Set step function timeout
asked 4 months ago
That's exactly what I was looking for, now sure how I missed it. Thanks!