SNS notification types (email, SMS, Lambda) in AWS - Time & Space Complexity
When sending notifications using SNS with different types like email, SMS, and Lambda, it's important to know how the number of notifications affects the work done.
We want to understand how the time to send notifications grows as we increase the number of messages.
Analyze the time complexity of the following operation sequence.
# Create SNS topic
aws sns create-topic --name MyTopic
# Subscribe email, SMS, and Lambda endpoints
aws sns subscribe --topic-arn arn:aws:sns:region:account:MyTopic --protocol email --notification-endpoint user@example.com
aws sns subscribe --topic-arn arn:aws:sns:region:account:MyTopic --protocol sms --notification-endpoint +1234567890
aws sns subscribe --topic-arn arn:aws:sns:region:account:MyTopic --protocol lambda --notification-endpoint arn:aws:lambda:region:account:function:MyFunction
# Publish message to topic
aws sns publish --topic-arn arn:aws:sns:region:account:MyTopic --message "Hello Subscribers"
This sequence sets up a topic with three types of subscribers and sends one message to all.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Publishing a message to the SNS topic.
- How many times: Once per message, but SNS fans out to all subscribers.
- Dominant operation: SNS sending notifications to each subscriber endpoint (email, SMS, Lambda).
Each message sent to the topic triggers SNS to send notifications to all subscribers.
| Input Size (n subscribers) | Approx. Notifications Sent |
|---|---|
| 10 | 10 notifications |
| 100 | 100 notifications |
| 1000 | 1000 notifications |
Pattern observation: The number of notifications grows directly with the number of subscribers.
Time Complexity: O(n)
This means the time to send notifications grows linearly with the number of subscribers.
[X] Wrong: "Sending one message to SNS means only one notification is sent regardless of subscribers."
[OK] Correct: SNS fans out the message to every subscriber, so the total notifications equal the number of subscribers.
Understanding how SNS scales with subscribers helps you design systems that handle many users efficiently and shows you can reason about cloud service behavior.
"What if we added message filtering so only some subscribers get notified? How would the time complexity change?"
Practice
Solution
Step 1: Review SNS supported protocols
AWS SNS supports protocols like email, sms, and lambda for subscriptions.Step 2: Identify unsupported protocol
FTP is not supported as a protocol for SNS subscriptions.Final Answer:
ftp -> Option DQuick Check:
Supported protocols exclude ftp [OK]
- Confusing FTP as supported protocol
- Thinking HTTP is the only protocol
- Mixing SNS with S3 protocols
Solution
Step 1: Understand protocol and endpoint types
For SMS, protocol must be 'sms' and endpoint is a phone number with country code.Step 2: Match correct protocol and endpoint
Protocol: 'sms', Endpoint: '+1234567890'correctly uses 'sms' protocol and a phone number endpoint.Final Answer:
Protocol: 'sms', Endpoint: '+1234567890' -> Option CQuick Check:
SMS needs phone number endpoint [OK]
- Using email as protocol for SMS
- Using email address as SMS endpoint
- Using lambda protocol with phone number
sns.subscribe({
Protocol: 'lambda',
Endpoint: 'arn:aws:lambda:us-east-1:123456789012:function:ProcessMessage'
});What happens when a message is published to this SNS topic?
Solution
Step 1: Identify protocol and endpoint meaning
Protocol 'lambda' means SNS invokes the specified Lambda function ARN when a message is published.Step 2: Understand message delivery behavior
The Lambda function 'ProcessMessage' is called with the message payload as input.Final Answer:
The Lambda function 'ProcessMessage' is invoked with the message payload. -> Option AQuick Check:
Lambda protocol triggers function invocation [OK]
- Thinking Lambda receives email or SMS
- Assuming subscription fails
- Confusing endpoint ARN with phone/email
Solution
Step 1: Understand email subscription confirmation
Email subscriptions require the recipient to confirm by clicking a link in a confirmation email.Step 2: Identify common cause of no delivery
If the email is not confirmed, SNS will not send notifications to that address.Final Answer:
The email address was not confirmed by the subscriber. -> Option AQuick Check:
Email subscriptions need confirmation [OK]
- Assuming SNS does not support email
- Confusing phone number as email endpoint
- Expecting Lambda involvement in email subscription
Solution
Step 1: Understand protocol and endpoint matching
SMS protocol requires a phone number endpoint; Lambda protocol requires Lambda function ARN.Step 2: Configure two subscriptions correctly
Create one subscription with protocol 'sms' and phone number endpoint, and another with protocol 'lambda' and Lambda ARN endpoint.Final Answer:
Create one subscription with protocol 'sms' and endpoint as phone number, and another with protocol 'lambda' and endpoint as Lambda ARN. -> Option BQuick Check:
Match protocol to correct endpoint type [OK]
- Mixing endpoints and protocols
- Using email protocol for SMS
- Assigning Lambda ARN as SMS endpoint
Ready to prove it?
Pass the test and this pattern moves unknown
