Lesson 5 of 5 Amazon CloudWatch Metrics and Alarms

Delivering Operational Notifications with Amazon SNS

This lesson covers configuring services to publish to Amazon SNS, which carries alarm notifications and service events to people and automation, and troubleshooting delivery.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish standard and FIFO topics and subscription types.
  • Identify the services that publish to SNS.
  • Configure topic access policies and KMS encryption.
  • Troubleshoot missing notifications.

Topics and subscriptions

A standard topic delivers each message to all subscriptions, in no guaranteed order; a FIFO topic preserves order and deduplicates but only delivers to SQS queues. Subscription protocols include email and email-JSON, SMS, HTTP and HTTPS endpoints, SQS queues, Lambda functions, Amazon Data Firehose and mobile push. Email and HTTP subscriptions must be confirmed before they receive messages; an unconfirmed email subscription is the most common reason why an operator receives nothing. A subscription filter policy delivers only messages whose attributes (or body) match, so one topic can serve teams with different interests.

Sort into groups

Which subscription?

Exam skills 1.1.5

Choose the SNS subscription protocol for each consumer.

Log in to try this activity Interactive activities are free with an account.

Services that publish to SNS

Many AWS services can publish notifications to an SNS topic directly, which is often the least-effort way to inform people. The following table lists the most common sources in operations scenarios.

SourceWhat it sends
CloudWatch alarmsState changes of metric and composite alarms
EC2 Auto ScalingInstance launch, termination and failed launch or termination
RDS event subscriptionsFailover, maintenance, backup, configuration and low-storage events
CloudFormationStack events during create, update and delete
AWS BackupBackup, copy and restore job events from a vault
S3 Event NotificationsObject created, removed, restored and replication events
AWS ConfigConfiguration item and compliance change notifications
Amazon EventBridgeAny matched event, through an SNS target

Access policies and encryption

The topic's access policy is a resource-based policy that must allow the publishing principal. For AWS services this is a service principal such as events.amazonaws.com, s3.amazonaws.com or cloudwatch.amazonaws.com, scoped with aws:SourceArn or aws:SourceAccount so that only your resources can publish. When the console creates an S3 event notification or an EventBridge target, it usually adds this statement; when the CLI or infrastructure as code is used, it must be added explicitly.

Server-side encryption with KMS adds a second requirement. The publishing service must be able to use the key, so the topic must use a customer managed key whose key policy allows the service principal kms:GenerateDataKey* and kms:Decrypt. The AWS managed key alias/aws/sns has a fixed policy that does not allow other services, so CloudWatch alarms and EventBridge rules publishing to a topic encrypted with it fail silently.

{
  "Sid": "AllowEventBridgePublish",
  "Effect": "Allow",
  "Principal": {"Service": "events.amazonaws.com"},
  "Action": "sns:Publish",
  "Resource": "arn:aws:sns:eu-west-1:111122223333:ops-alerts",
  "Condition": {"ArnLike": {"aws:SourceArn": "arn:aws:events:eu-west-1:111122223333:rule/*"}}
}

The following diagram compares a topic encrypted with a customer managed key with one using the AWS managed key.

What a service needs to publish to an encrypted SNS topic. The topic's access policy must allow the service principal, such as cloudwatch.amazonaws.com, scoped with aws:SourceArn. If the topic is encrypted, it must use a customer managed key whose key policy allows that service kms:GenerateDataKey* and kms:Decrypt; the AWS managed key alias/aws/sns cannot allow other services.
Silent alarms with no delivery errors in SNS usually point to one of these two policies.
Troubleshooting scenario

Why is nothing published?

Exam skills 1.1.5 · 4.2.2

Find why messages are not reaching an SNS topic.

Log in to try this activity Interactive activities are free with an account.
Worked example

Troubleshooting missing notifications

After a security review encrypted every SNS topic, operators stopped receiving alarm emails, although the alarms still reach the ALARM state. The troubleshooting order is as follows.

  1. Read the alarm history

    Look for an action failure message.

  2. Check the topic's key

    If it is alias/aws/sns, re-encrypt with a customer managed key.

  3. Allow CloudWatch in the key policy

    Allow cloudwatch.amazonaws.com to use kms:GenerateDataKey* and kms:Decrypt.

  4. Check the topic policy and subscriptions

    Confirm the topic policy allows CloudWatch to publish and that subscriptions are confirmed.

  5. Check subscriber-side delivery

    Use SNS delivery status logging and the NumberOfNotificationsFailed metric.

Check yourself

Which condition should a topic policy use to limit publishing to one alarm or bucket?

Show answer

aws:SourceArn, which restricts the service principal to publishing on behalf of that specific resource.

Exam Tips

Remember for the exam

  • Unconfirmed email subscriptions receive nothing.
  • Services publishing to an encrypted topic need a customer managed KMS key that allows them.
  • Topic access policies must allow the publishing service principal, ideally with aws:SourceArn.
  • Use subscription filter policies to send different messages to different subscribers.
  • Auto Scaling, RDS, CloudFormation, AWS Backup and S3 can all notify SNS directly.