sns-sqs-fanout
Source on GitHub · All examples
One SNS publish is delivered to every SQS queue subscribed to the topic.
What it shows
aws sns create-topicfororders.aws sqs create-queueforbillingandshipping.aws sns subscribefor both queues.aws sns publishwith one JSON message.aws sqs receive-messageon both queues. Each gets the message.
Prerequisites
- Docker, AWS CLI v2.
Run
bash
docker compose up -d --build
export AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test AWS_DEFAULT_REGION=us-east-1
./demo.shSet ENDPOINT to use a server other than http://localhost:8000.
Expected output
TopicArn: arn:aws:sns:us-east-1:000000000000:orders
=== Receive from billing ===
{"Messages": [{"Body": "{\"Type\":\"Notification\", ... \"Message\":\"{\\\"orderId\\\":\\\"o-123\\\",\\\"total\\\":42.5}\" ...}"}]}
=== Receive from shipping ===
{"Messages": [{"Body": "{\"Type\":\"Notification\", ... }]}
=== SUCCESS: one publish fanned out to both queues ===The CLI prints the JSON pretty-printed. The script exits non-zero if either queue is empty.
Clean up
bash
docker compose down -v