Hands-On: Topics & Subscriptions

Create a topic, subscribe your email, and publish a message.

1 min read

Email subscriptions must be confirmed by clicking a link SNS sends. That protects people from being subscribed without consent.

Try it

Terminal
TOPIC=$(aws sns create-topic --name notesnap-summary-ready --query TopicArn --output text)

aws sns subscribe --topic-arn $TOPIC --protocol email \
  --notification-endpoint you@example.com
# Check your inbox and click "Confirm subscription"

aws sns publish --topic-arn $TOPIC \
  --subject "Your note is summarized" \
  --message "todo.txt: Finish the S3 tutorial before moving on to Lambda." \
  --message-attributes '{"noteType":{"DataType":"String","StringValue":"todo"}}'

From Python, publishing is one call:

Python
import boto3
boto3.client("sns").publish(TopicArn=TOPIC_ARN, Subject="Hello", Message="It works!")
Note

SMS has extra setup in most countries (origination numbers or sender IDs, plus spending limits). For app notifications, email, mobile push, or in-app messages are usually simpler.

Key takeaways

  • create-topic → subscribe → publish is the whole flow.
  • Email subscriptions must be confirmed by the recipient.
  • Message attributes add metadata that subscribers can filter on.

Check your understanding

Pick an answer to see the explanation.

  1. 1. You subscribed an email address but nothing arrives. What's the first thing to check?