0
0
AWScloud~10 mins

SNS topics and subscriptions in AWS - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - SNS topics and subscriptions
Create SNS Topic
Create Subscription
Publish Message to Topic
SNS Delivers Message to Subscribers
Subscribers Receive Message
This flow shows how an SNS topic is created, subscriptions are added, messages are published, and then delivered to subscribers.
Execution Sample
AWS
aws sns create-topic --name MyTopic
aws sns subscribe --topic-arn <topic-arn> --protocol email --notification-endpoint user@example.com
aws sns publish --topic-arn <topic-arn> --message "Hello Subscribers!"
This code creates an SNS topic, subscribes an email endpoint, and publishes a message to the topic.
Process Table
StepActionInputOutputState Change
1Create SNS TopicName=MyTopicTopicArn=arn:aws:sns:region:account:MyTopicTopic created with ARN
2Subscribe to TopicTopicArn=arn:aws:sns:region:account:MyTopic, Protocol=email, Endpoint=user@example.comSubscriptionArn=arn:aws:sns:region:account:MyTopic:sub-idSubscription added to topic
3Publish MessageTopicArn=arn:aws:sns:region:account:MyTopic, Message="Hello Subscribers!"MessageId=msg-idMessage queued for delivery
4Deliver MessageMessageId=msg-idSuccessMessage sent to subscriber endpoint
5Subscriber Receives MessageEmail inboxMessage content: "Hello Subscribers!"Subscriber notified
6EndNo further actionsN/AProcess complete
💡 All subscribers have received the published message, process ends.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
TopicArnNonearn:aws:sns:region:account:MyTopicarn:aws:sns:region:account:MyTopicarn:aws:sns:region:account:MyTopicarn:aws:sns:region:account:MyTopicarn:aws:sns:region:account:MyTopic
SubscriptionArnNoneNonearn:aws:sns:region:account:MyTopic:sub-idarn:aws:sns:region:account:MyTopic:sub-idarn:aws:sns:region:account:MyTopic:sub-idarn:aws:sns:region:account:MyTopic:sub-id
MessageIdNoneNoneNonemsg-idmsg-idmsg-id
MessageDeliveredFalseFalseFalseFalseTrueTrue
Key Moments - 3 Insights
Why do we need to create a subscription after creating a topic?
Creating a topic only sets up the channel. Subscriptions tell SNS where to send messages. See execution_table step 2 where subscription is added after topic creation.
What happens if no subscriptions exist when a message is published?
SNS accepts the message but has no endpoints to deliver to, so no delivery occurs. This is implied by the need for subscriptions in step 2 before publishing in step 3.
Does publishing a message guarantee delivery to subscribers immediately?
Publishing queues the message for delivery (step 3), but actual delivery happens next (step 4). Delivery depends on subscriber availability.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the TopicArn value after step 1?
Aarn:aws:sns:region:account:MyTopic
BNone
Carn:aws:sns:region:account:MyTopic:sub-id
Dmsg-id
💡 Hint
Check the 'TopicArn' row in variable_tracker after step 1.
At which step does the message get queued for delivery?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Action' and 'State Change' columns in execution_table for message publishing.
If no subscriptions were created, what would happen at step 4?
AMessage would be delivered to subscribers
BSNS would throw an error and stop
CMessage would be queued but not delivered
DMessage would be deleted immediately
💡 Hint
Refer to key_moments about publishing without subscriptions.
Concept Snapshot
SNS Topics and Subscriptions:
- Create a topic to act as a message channel.
- Add subscriptions to specify where messages go.
- Publish messages to the topic.
- SNS delivers messages to all subscribers.
- Subscribers receive notifications asynchronously.
Full Transcript
This visual execution shows how AWS SNS topics and subscriptions work. First, a topic is created which acts like a message channel. Then, subscriptions are added to tell SNS where to send messages, such as an email address. When a message is published to the topic, SNS queues it and then delivers it to all subscribed endpoints. The subscriber finally receives the message. Variables like TopicArn, SubscriptionArn, and MessageId track the state through each step. Key moments clarify why subscriptions are needed and how delivery works. The quiz tests understanding of these steps and states.