Easy ReviewDOP-C02
Incident and Event Response32

SNS

Publish to multiple subscribers, filter each delivery path, and protect SNS-to-SQS delivery and recovery.

Amazon SNS connects event publishers to application and human subscribers. Subscription filters select messages; queue policies, encryption permissions, and dead-letter queues govern each delivery path.

Topics, subscriptions, and fan-out

Amazon SNS is a publish/subscribePublish/subscribe sends messages through a topic to recipients attached by subscriptions. service: a publisher sends a message to a topicA topic is a named communication channel to which publishers send messages., and subscriptionsA subscription connects a topic to an endpoint that receives its messages. connect that topic to recipient endpointsAn endpoint is the destination that receives an SNS notification.. Fan-outFan-out delivers one publication to multiple subscribers. means delivering a publication to several independent subscribers.

How it works

  1. Choose a topic type and attach subscriptions for the recipients. Standard topics can deliver duplicates and messages out of publication order, so applications must handle both.

    Destination on a Standard topic Use
    SQS Retain messages for later processing
    Lambda Run application logic
    HTTP or HTTPS Send to a web endpoint
    Email Notify people
    SMS Notify a phone number by text
    Mobile push Notify a mobile application
    Data Firehose Send events to a delivery stream
  2. Confirm email and HTTP(S) subscriptions before expecting notifications. HTTP(S) endpoints must accept SNS POST requests, including subscription confirmation.

  3. Publish to the topic. SNS pushes to subscribers; SQS consumers pollPolling asks a queue for messages waiting to be processed., meaning they ask the queue for waiting messages. Separate queues let independent applications retain and process their own copies.

  4. For ordered processing, combine an SNS FIFOFIFO preserves message order within each message group when used with FIFO delivery destinations. topic with an SQS FIFO queue. FIFO means first in, first out. Set MessageGroupId to identify events whose order must be preserved. Ordering applies within a group.

  5. For deployment notifications, configure a CodeDeploy deployment-group event trigger to send events, including failures, to an SNS topic.

Exam cues

  • If the question says every application needs an independent copy and can be temporarily offline, think SNS with one SQS queue per application, because each queue retains its delivered messages.
  • If the question says deployment failure email without polling, think a native CodeDeploy trigger to SNS, because the deployment group can emit the event directly.
  • If the question says an email subscription receives nothing, think confirmation, because SNS waits for the recipient to confirm.
  • If the question says an EC2 instance should subscribe to an SNS topic, think Lambda, SQS or HTTPS subscribers instead, because an instance is not an SNS subscription type.

Remember

  • SNS pushes; SQS consumers poll.
  • Standard topics: at-least-once delivery and best-effort ordering.
  • SNS FIFO can deliver to Standard queues, but strict consumer ordering requires FIFO queues.
  • FIFO topics do not directly support email, HTTP(S), SMS, or mobile push.
  • FIFO topics store messages across multiple Availability Zones.
  • SSEServer-side encryption protects stored message contents using an encryption key. encrypts message bodies only, with symmetric KMS keys.
  • Delivery status logging covers endpoints such as SQS, Lambda, Firehose and HTTP/S.

Trap: An SNS FIFO topic alone cannot preserve ordered processing through an SQS Standard queue. Choose a FIFO queue when consumer ordering matters.

One publication, separate subscriber queues
publish1copy A2copy B3PublisheriSNS topiciConsumer A queueiConsumer B queuei
  1. The publisher sends one message to SNS.

  2. SNS pushes the message to the first subscribed queue.

  3. SNS also pushes the message to the other subscribed queue; each application polls its own queue.

Box details (4)
Publisher

A publisher sends a message to the topic.

SNS topic

SNS pushes a copy to each matching subscription.

Consumer A queue

The queue retains messages for its application to poll later.

Consumer B queue

A separate subscription delivers to a separate queue for the other application.

From the AWS docs (19)
  • SNS asynchronously delivers messages from publishers to subscribers through topics.
  • SNS Standard topic destinations include SQS, Lambda, HTTP(S), email, SMS, mobile push, and Data Firehose.
  • SNS pushes notifications; SQS retains messages for applications to process later through polling.
  • A topic can deliver a published message to multiple subscribed SQS queues.
  • Email subscriptions must be confirmed before receiving messages and are supported directly only on Standard topics.
  • HTTP(S) endpoints must handle SNS POST requests and confirm the subscription before notifications arrive.
  • SNS FIFO topics deliver to SQS FIFO and Standard queues; strict consumer ordering requires a FIFO queue.
  • SNS FIFO topics cannot directly deliver to email, HTTP(S), SMS, or mobile push endpoints; Lambda integration uses a subscribed SQS queue.
  • SNS FIFO publishers set MessageGroupId; ordering is maintained within each message group.
  • CodeDeploy deployment-group triggers send deployment events, including failures, to an SNS topic.
  • SNS Standard topics provide at-least-once delivery and best-effort ordering, so duplicates and out-of-order messages can occur.
  • SNS subscription endpoint types are HTTP/HTTPS, email, Amazon SQS, AWS Lambda, Amazon Data Firehose, platform application endpoints (mobile push) and SMS; an EC2 instance is not an endpoint type of its own.
  • AWS End User Messaging SMS, the former SMS, MMS and voice features of Amazon Pinpoint, is an application-to-person messaging service for SMS, MMS, RCS and voice.
  • With two-way SMS, AWS End User Messaging SMS receives incoming replies from customers, which can feed services such as Lambda or Amazon Lex.
  • SNS topics accept messages up to 256 KiB by default; the MaximumMessageSize topic attribute raises this to 1 MiB, and topics above 256 KiB support Firehose, SQS and Lambda subscriptions.
  • An SNS FIFO topic accepts but does not deliver a message whose deduplication ID was already published within the five-minute deduplication interval.
  • SNS FIFO topics and SQS queues store messages redundantly across multiple Availability Zones.
  • SNS server-side encryption encrypts message bodies with symmetric KMS keys only; topic metadata and message metadata such as subject, ID and attributes are not encrypted.
  • SNS can log the delivery status of messages to endpoints such as Amazon SQS, AWS Lambda, Data Firehose and HTTP/S.

Subscription filters

An SNS subscriptionA subscription connects a topic to an endpoint that receives its messages. filter selects messages before delivery to that subscriber. A message attributeA message attribute is a named metadata value published alongside the message body. is named metadata sent alongside the payloadA payload is the application data carried inside a message., while the message body is the payload itself.

How it works

  1. Attach a JSON filter policyA filter policy selects which messages SNS delivers to a particular subscription. to the subscription that needs a subset of messages. Subscriptions without a policy receive every publication.

  2. Select the filter scope: MessageAttributes is the default; MessageBody inspects a well-formed JSON payload.

  3. Define the properties and accepted values. Each named policy property must match, and at least one accepted value must match for each property. Extra message properties do not affect the result.

  4. Choose operators that express the selection.

    Match type Use
    Exact string A particular named value
    Prefix or suffix A string beginning or ending with a selected value
    Anything-but A value outside an excluded selection
    Numeric match A number matching the chosen condition
  5. SNS delivers matching messages to that subscription and omits nonmatches.

Exam cues

  • If the question says a routing field is inside the JSON payload, think MessageBody, because the default scope looks at attributes.
  • If the question says different subscribers need different event categories, think subscription filter policies, because each subscription selects its own messages.

Remember

  • Default scope: MessageAttributes.
  • Body scope: MessageBody, requiring a well-formed JSON object.
  • All named policy properties must match; values within a property provide alternatives.

Trap: Creating a filter for a body field while leaving the default scope unchanged does not make SNS inspect the body.

From the AWS docs (9)
  • Without a filter policy, an SNS subscription receives every message published to its topic.
  • A filter policy is a JSON object attached to a subscription that selects which messages SNS sends to that subscriber.
  • FilterPolicyScope defaults to MessageAttributes.
  • FilterPolicyScope: MessageBody applies filtering to message-body properties.
  • Message-body filtering assumes the payload is a well-formed JSON object.
  • Each policy property must match a corresponding message attribute or body property, with at least one matching value per property.
  • Message attributes or body properties not specified in the filter policy are ignored during evaluation.
  • SNS filtering supports exact string matching, prefixes, suffixes, anything-but, numeric matching, and other documented operators.
  • SNS does not deliver a message to a subscription when it fails that subscription filter.

SQS delivery policies and encryption

SNS-to-SQS delivery needs both a subscriptionA subscription connects a topic to an endpoint that receives its messages. and destination permission. Encryption adds a separate key authorization check, while a subscription dead-letter queueA dead-letter queue stores messages SNS could not deliver to a subscription endpoint. (DLQ) retains notifications that SNS cannot deliver.

How it works

  1. Subscribe the SQS queue using its Amazon Resource NameAn ARN identifies an AWS resource such as a topic or queue. (ARN), the identifier of the destination resource.

  2. In the queue policy, allow the SNS service principalA service principal identifies an AWS service in an access policy., sns.amazonaws.com, to perform sqs:SendMessage. Restrict aws:SourceArn to the publishing topicA topic is a named communication channel to which publishers send messages..

  3. For a queue encrypted with a customer managed KMS key, allow SNS kms:GenerateDataKey and kms:Decrypt on that key. If the SNS topic is also encrypted, publishers need their own topic-key permissions too. SNS requires symmetric keysA symmetric encryption key uses the same key material for encryption and decryption., which use the same key to encrypt and decrypt data.

  4. Choose the payloadA payload is the application data carried inside a message. format. Ordinary delivery includes an SNS JSON envelopeAn SNS envelope wraps a published message with SNS notification metadata., a wrapper containing the message and SNS metadata. RawMessageDelivery: true sends the original body to SQS without that wrapper.

  5. Handle failure according to its cause.

    Failure or policy Behavior
    Retryable server-side failure at SQS or Lambda SNS policy provides 100015 attempts over 23 days
    Client-side error, such as a destination policy denial SNS does not retry
    HTTP(S) custom retry policy Supported, with total retry time at most 3600 seconds
    Retries exhausted Message is discarded unless a subscription DLQ is attached
  6. Set a RedrivePolicy on the subscription to name an SQS DLQ in the same account and Region. Standard topic subscriptions use Standard DLQs; FIFOFIFO preserves message order within each message group when used with FIFO delivery destinations. topic subscriptions use FIFO DLQs. An encrypted DLQ also needs a customer managed key that grants SNS access.

Exam cues

  • If the question says a queue subscription exists but messages do not arrive, think queue access policy and KMS key policy, because subscription creation does not replace delivery authorization.
  • If the question says preserve notifications when an endpointAn endpoint is the destination that receives an SNS notification. cannot receive them, think a subscription redrive policyAn SNS redrive policy identifies the SQS queue that receives a subscription's undeliverable messages., because the DLQ belongs to each delivery path.
  • If the question says an SQS consumer cannot parse an SNS wrapper, think raw message delivery, because it removes the notification envelope.

Remember

  • Queue permission: sqs:SendMessage for sns.amazonaws.com, restricted by topic ARN.
  • Queue KMS permissions: kms:GenerateDataKey and kms:Decrypt.
  • Encrypted-topic publisher permissions: kms:GenerateDataKey* and kms:Decrypt; SNS supports symmetric keys only.
  • Raw SQS delivery: maximum 10 attributes; messages above that count are discarded as client-side errors.
  • Recommended subscription DLQ retention: 14 days.

Trap: Topic-key permission does not authorize the destination queue or its key. Each resource has its own policy.

SNS subscription delivery and failure recovery
123SNS topiciSQS destinationiDelivery failureiSubscription DLQi
  1. SNS attempts delivery to the subscribed queue.

  2. A client-side error or exhausted retries leaves the message undeliverable.

  3. The subscription redrive policy sends the message to its DLQ.

Box details (4)
SNS topic

A publication enters a queue subscription.

SQS destination

The queue and its KMS key must authorize delivery.

Delivery failure

Client-side failures or exhausted retries leave a message undeliverable.

Subscription DLQ

The subscription redrive policy preserves the failed message in an SQS queue.

From the AWS docs (17)
  • An SQS queue policy must allow sns.amazonaws.com to call sqs:SendMessage, scoped with aws:SourceArn to the permitted SNS topic.
  • The SQS queue must be subscribed to the SNS topic using the queue ARN.
  • For an SQS queue encrypted with a customer managed KMS key, the key policy must allow the SNS service principal kms:GenerateDataKey and kms:Decrypt.
  • Publishing to an encrypted SNS topic requires kms:GenerateDataKey* and kms:Decrypt permissions on the topic key in addition to SNS publish permission.
  • SNS topic encryption supports symmetric KMS keys only.
  • RawMessageDelivery: true strips the SNS JSON envelope for SQS delivery and sends the published message body as-is.
  • Raw SQS delivery supports at most 10 message attributes; SNS discards messages with more attributes as client-side errors.
  • SNS retries server-side delivery errors according to the endpoint protocol; after retry exhaustion it discards the message unless a subscription DLQ is configured.
  • For retryable errors at SQS and Lambda endpoints, the SNS delivery policy provides 100015 attempts over 23 days.
  • Only HTTP(S) delivery policies can be customized; their total retry time cannot exceed 3600 seconds.
  • SNS does not retry delivery failures caused by client-side errors such as a destination policy blocking access.
  • An SNS subscription redrive policy targets an SQS dead-letter queue for messages SNS cannot deliver; the policy is on the subscription rather than the topic.
  • An SNS subscription and its dead-letter queue must be in the same account and Region.
  • Standard topic subscriptions use Standard dead-letter queues; FIFO topic subscriptions use FIFO dead-letter queues.
  • AWS recommends a 14-day retention period for SNS subscription dead-letter queues.
  • An encrypted SNS subscription dead-letter queue requires a customer managed KMS key that grants the SNS service principal key access.
  • Symmetric encryption uses the same key to encrypt and decrypt data.

Operational notifications and filter changes

Amazon SNS can carry operational notifications from several AWS services. The configuration depends on the event source, and subscriptionA subscription connects a topic to an endpoint that receives its messages. filter changes need time to take effect.

How it works

  1. Select the event source and its notification path:

    Event source Path to SNS
    EC2 Auto Scaling Select launch or termination notification types, including error types for failures.
    Systems Manager Send Run Command or Maintenance Windows status changes to an SNS Standard topicA topic is a named communication channel to which publishers send messages.. An invocation is a command sent to an individual node.
    AWS Organizations Configure an EventBridge rule in us-east-1 with SNS as the target.
    AWS Trusted Advisor Monitor check metrics with a CloudWatch alarm in us-east-1 and notify SNS.
    Amazon Aurora Allow the RDS event service to publish in the destination topic policy.
  2. When a subscription filter policyA filter policy selects which messages SNS delivers to a particular subscription. is added or changed, allow for eventual consistencyEventual consistency means a policy update takes time to become effective throughout the service.: the change can take up to 15 minutes to fully take effect.

Exam cues

  • If the question says an Auto Scaling launch or termination failed, think notification types ending in _ERROR, because the types without that suffix report success.
  • If the question says a command failed on an individual node, think Systems Manager invocation status notifications on a Standard topic, because an invocation is the per-node command.
  • If the question says Organizations account activity or Trusted Advisor check changes need SNS notifications, think us-east-1, because the paths use an EventBridge rule or a CloudWatch alarm there, respectively.
  • If the question says Aurora event notifications need to reach SNS, think the destination topic policy, because it must allow the RDS event service to publish.
  • If the question says a filter behaves inconsistently just after an update, think eventual consistency, because the change may still be propagating.

Remember

  • Auto Scaling success types: autoscaling:EC2_INSTANCE_LAUNCH and autoscaling:EC2_INSTANCE_TERMINATE. Failure types add _ERROR.
  • Systems Manager status notifications use SNS Standard topics.
  • Filter policy additions and changes can take up to 15 minutes to fully take effect.

Trap: A newly changed filter policy may not take effect immediately. Allow up to 15 minutes before judging its behavior.

From the AWS docs (7)
  • Filter policy additions or changes can take up to 15 minutes to fully take effect.
  • Auto Scaling SNS notification types autoscaling:EC2_INSTANCE_LAUNCH and autoscaling:EC2_INSTANCE_TERMINATE report successful instance launch and termination.
  • Auto Scaling SNS notification types autoscaling:EC2_INSTANCE_LAUNCH_ERROR and autoscaling:EC2_INSTANCE_TERMINATE_ERROR report failed launch and termination.
  • Systems Manager Run Command and Maintenance Windows can publish command or per-node invocation status changes to SNS Standard topics.
  • Organizations activity can trigger EventBridge rules in us-east-1 with SNS as a notification target.
  • Trusted Advisor check metrics in us-east-1 can be monitored by CloudWatch alarms that notify SNS.
  • Aurora event notifications use an SNS destination topic whose policy allows the RDS event service to publish.

Flashcards

tap to flip
Answer

·

All 32 cards as a list

What do an Amazon SNS topic and subscription represent?

A topic is the publication channel. A subscription connects a recipient endpoint to that channel for message delivery.

Two independent applications must each receive every SNS event and process it when ready. What design should the team use?

Subscribe a separate SQS queue for each application to the SNS topic. SNS fans out messages and SQS retains them for each application to poll.

An SNS Standard topic must notify people and trigger applications. Which destination types can it use?

SQS, Lambda, HTTP(S), email, SMS, mobile push, and Data Firehose.

An SNS email subscription exists but receives no messages. What subscription step should be checked first?

Confirmation. The recipient must confirm the email subscription before receiving notifications.

Can an SNS FIFO topic directly notify an email address or HTTP endpoint?

No. Those direct endpoints require Standard topics. For Lambda processing from FIFO topics, use a subscribed SQS queue as the function event source.

An SNS workflow needs consumer ordering for events belonging to each customer. Which topic, queue, and field fit?

Use an SNS FIFO topic with an SQS FIFO queue and assign MessageGroupId by customer. Ordering is within each message group.

A team needs email when a CodeDeploy deployment fails, without adding a polling function. How can SNS be used?

Configure a failure-event trigger on the CodeDeploy deployment group with an SNS topic, and confirm the email subscription.

An SNS Standard subscriber receives a duplicate message and another message out of publication order. Is this outside the topic delivery contract?

No. Standard topics provide at-least-once delivery and best-effort ordering. Subscriber applications must be able to process duplicates and out-of-order messages.

A team wants an EC2 instance to subscribe directly to an SNS topic so it can react to alarm notifications. Is that possible?

No. SNS delivers to SQS, Lambda, HTTP or HTTPS, email, SMS, mobile push and Data Firehose, not to an instance. Subscribe a Lambda function or an SQS queue the instance polls.

Can an Amazon EC2 instance subscribe to an SNS topic directly?

Not as an endpoint type. SNS delivers to HTTP/HTTPS, email, SQS, Lambda, Firehose, mobile push and SMS; an app on EC2 would expose an HTTP endpoint or read from an SQS queue.

An application publishes events that several independent workers must process at their own pace. How can Amazon SNS and Amazon SQS support this?

Subscribe a separate SQS queue for each worker to an SNS topic. SNS fans out each message, and the queues retain messages for later polling.

A publisher must send 700 KiB messages through an SNS topic to SQS and Lambda subscribers. Is S3 offloading required?

Not necessarily. Set the topic MaximumMessageSize attribute, up to 1 MiB. The default is 256 KiB, and larger topics support Firehose, SQS and Lambda subscriptions.

An Amazon SNS topic uses server-side encryption. Is a sensitive value placed in a message attribute protected?

No. SSE encrypts the message body only; message attributes, subject and topic metadata stay unencrypted.

A team must confirm whether Amazon SNS messages reached an SQS queue and a Lambda function. Which SNS feature helps?

Delivery status logging for those endpoints.

An SNS subscriber needs only messages matching attributes or body content. What should the team configure?

A subscription filter policy. It evaluates MessageAttributes by default; set FilterPolicyScope to MessageBody for a well-formed JSON body.

An SNS message contains a routing field only inside its JSON body, but the subscription filter still uses the default scope. What should change?

Set FilterPolicyScope to MessageBody. The default MessageAttributes scope does not inspect body fields.

An SNS subscription filter names region and severity. The message matches severity but not region. Will SNS deliver it?

No. Each policy property must match, with at least one matching value for every property.

Does an additional SNS message attribute absent from the subscription filter make the message fail filtering?

No. SNS ignores properties that the policy does not specify.

What does an SNS subscription receive if no filter policy is assigned?

Every message published to its topic, subject to successful delivery.

What permissions does SNS need to deliver into an SQS queue encrypted with a customer managed KMS key?

The queue policy must allow sns.amazonaws.com to call sqs:SendMessage, restricted to the topic ARN. The queue KMS key policy must also permit SNS to call kms:GenerateDataKey and kms:Decrypt.

An SNS subscription exists, but an SQS destination policy no longer permits delivery. Will retries eventually fix it?

No. A policy denial is a client-side delivery error, which SNS does not retry. Restore the queue policy and configure a subscription dead-letter queue for failed deliveries.

Where should an SNS team configure an SQS dead-letter queue to retain failed notifications?

On each SNS subscription through its redrive policy. The subscription and DLQ must be in the same account and Region.

Can an SNS team customize retries for SQS subscriptions in the same way as HTTP subscriptions?

No. Custom delivery policies are supported only for HTTP(S), with a maximum total retry time of 3600 seconds.

An SQS consumer expects the original application JSON but receives an SNS notification envelope. Which subscription setting helps?

Set RawMessageDelivery to true. It removes the SNS envelope for SQS delivery; keep message attributes within the 10-attribute limit.

SNS delivers retryable errors to an SQS endpoint. What retry policy applies before moving undeliverable messages to a configured subscription DLQ?

The AWS managed endpoint policy provides 100015 attempts over 23 days. The DLQ retains messages SNS ultimately cannot deliver.

What SQS DLQ type and retention should an SNS FIFO subscription use?

A FIFO DLQ in the same account and Region. AWS recommends a 14-day retention period.

Does granting SNS access to a topic encryption key automatically authorize delivery into a separately encrypted SQS queue?

No. Publishing to an encrypted topic and writing to an encrypted queue use separate permissions. Configure the queue policy and its KMS key policy too.

A new SNS subscription filter seems to behave inconsistently immediately after an update. What documented behavior explains this?

Eventual consistency. Filter policy changes can take up to 15 minutes to fully take effect.

Which Auto Scaling notification types send successful launch and termination events to SNS?

autoscaling:EC2_INSTANCE_LAUNCH and autoscaling:EC2_INSTANCE_TERMINATE. Failure variants end in _ERROR.

A Systems Manager operator needs SNS notifications for failed commands on individual nodes. What should be configured?

Run Command SNS status notifications at invocation level, selecting the failure states, with an SNS Standard topic.

A team needs SNS notifications for Organizations account activity or Trusted Advisor check changes. Where should the routing be configured?

In us-east-1. Use Organizations EventBridge rules targeting SNS, or CloudWatch alarms on Trusted Advisor metrics with an SNS action.

Aurora event notifications must reach an SNS topic. What access policy is required at the destination?

The SNS topic policy must allow the RDS event service to publish the database event notifications.

You finished every topic of DOP-C02!

Your badge turned gold. Next step: book the exam on AWS. Once you pass, add yourself to Who passed.

Share

Share that you finished this certification

I finished every topic of AWS Certified DevOps Engineer - Professional (DOP-C02) on Easy Review. Come study too!