SNS
Simple Notification Service(SNS) is a highly available publish/Subscribe messaging service. The pub/sub pattern allows publishers to send messages without the knowledge of who they need to be sent
An SNS Topic is a communication channel to link together publishers and subscribers. The publisher is sending messages to a specific topic and these messages are then being delivered to the subscribers
SNS Benefits
- Decouple services: Publishers don’t need to know about their subscribers which allows us to decouple services
- One message can be sent to many subscribers
- Highly available
- Compatible with many AWS services which can be used as source and destination.
Cloudwatch
Cloudwatch is an AWS monitoring service that allows you to ingest logs and metrics from the applications or services. Cloudwatch alarms can be configured to be raised when the metrics meet certain criteria.
For example: You can set alarms to be notified about low disk space or high CPU usage.
Cloudwatch can sent messages directly to an SNS topic and SNS allows to setup an email address for the messages to be sent to. So, Cloudwatch will act as a publisher and the email account will act as the subscriber. This allows Cloudwatch to send email notifications
Creating SNS Topic
- Go to SNS → Select Topics
- Click on Create Topic → Specify the Topic Name → Select Create Topic
- Add email subscription to the Topic:
- On the Topic Details page, Select Create Subscription → Choose Email from the protocoldrop-down list.
- Type the email address in the endpoint
- Click on Create Subscription
- Confirm the subscription using the confirmation link sent to the specified email
Creating CloudWatch Alarm
- Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
- In the navigation panel, choose Alarms → All alarms.
- Choose Create alarm.
- Choose Select Metric and select the desired metric.
- In the Specify metric and conditions page, edit the statistics and period as required.
- Under Conditions, choose threshold type as static.
- For Whenever metric_nameis, specify whether the metric must be greater than, less than, or equal to the threshold.
- Under than… field, specify the threshold value.
- Choose next
- Under Notification, select an SNS topic to notify when the alarm is in ALARM state, OK state, or INSUFFICIENT_DATA state.
- To have the alarm send multiple notifications for the same alarm state or for different alarm states, choose Add notification.
- To have the alarm not send notifications, choose Remove.
- When finished, choose Next.
- Enter a name and description for the alarm. Then choose Next.
- Under Preview and create, confirm that the information and conditions are what you want, then choose Create alarm.
Whenever the selected metric value goes above the specified threshold an alert will be created and the notification is sent to the subscriber added in the SNS Topic.