Amazon SNS to Amazon SQS

SNS → SQS

Create an SQS queue that subscribes to an SNS topic.

This CDK template deploys a SNS topic and an SQS queue. The SQS queue is subscribed to the SNS topic. SNS invokes the SQS queue when new messages are available. When messages are sent to the SNS topic, they are delivered as a JSON event payload to the SQS queue.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/sns-sqs-cdk

Deploy

See the GitHub repo for detailed deployment instructions.


Testing

Use the AWS CLI to send a message to the SNS topic and observe the event delivered to the Lambda function:
1. Send the SNS message: aws sns publish --topic-arn ENTER_SNS_TOPIC_ARN --subject testSubject --message testMessage.
2. Retrieve the message from the SQS queue, using the queue URL from the AWS SAM deployment outputs: aws sqs receive-message --queue-url ENTER_YOUR_QUEUE_URL.

Cleanup

1. Delete the stack: npx cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus".
3. You see a message confirming DELETE_COMPLETE.

Created by:

Ian Larson

Ian Larson

Ian is a Sr. Cloud Infrastructure Architect with AWS. When he's not building cloud solutions with AWS customers, he can be found on his bike exploring the roads less traveled.