Day 46: Set up CloudWatch alarms and SNS topic in AWS

Radheya Zunjur
5 min readAug 11, 2023

--

Welcome to Day 46 of our comprehensive journey through Amazon Web Services (AWS) cloud computing! In today’s installment, we delve into the pivotal realm of monitoring and notifications by exploring the setup of CloudWatch alarms and Simple Notification Service (SNS) topics within the AWS ecosystem.

What is Amazon CloudWatch?

Amazon CloudWatch monitors your Amazon Web Services (AWS) resources and the applications you run on AWS in real time. You can use CloudWatch to collect and track metrics, which are variables you can measure for your resources and applications.

Key features of Amazon CloudWatch include:

  1. Metrics Collection: CloudWatch allows you to collect and visualize metrics (numerical data) from various AWS services, such as EC2 instances, RDS databases, Lambda functions, and more. These metrics can be used to monitor the utilization, performance, and behavior of your resources over time.
  2. Dashboards: You can create custom dashboards that display a visual representation of your collected metrics. Dashboards provide a convenient way to monitor the health and performance of your resources at a glance.
  3. Alarms: CloudWatch enables you to set up alarms based on defined thresholds for your metrics. When these thresholds are breached, CloudWatch can trigger notifications (via email, SMS, or integration with other AWS services) to alert you of potential issues or opportunities for optimization.
  4. Logs Monitoring: CloudWatch Logs allows you to collect, store, and analyze log data from various sources, including applications, services, and custom sources. You can search, filter, and gain insights from log data to troubleshoot issues and understand system behavior.
  5. Event-driven Automation: CloudWatch Events helps you respond to changes in your AWS environment by detecting and responding to events. This can involve triggering actions, such as launching EC2 instances or invoking Lambda functions, in response to specific events or patterns.
  6. Insight and Analysis: CloudWatch offers various tools for analyzing and gaining insights from your collected metrics and log data, including CloudWatch Metrics Explorer and CloudWatch Logs Insights.
  7. Integration: CloudWatch can be integrated with other AWS services, such as AWS Lambda, AWS SNS (Simple Notification Service), and AWS EC2 Auto Scaling, to enable dynamic and automated responses to changes in your environment.

What is Amazon SNS?

Amazon Simple Notification Service is a notification service provided as part of Amazon Web Services since 2010. It provides a low-cost infrastructure for mass delivery of messages, predominantly to mobile users.

Key features of Amazon SNS include:

  1. Message Publishing: Amazon SNS allows you to publish messages to topics. A topic is a communication channel to which multiple subscribers can subscribe. When a message is published to a topic, it is delivered to all active subscribers of that topic.
  2. Subscriber Flexibility: Subscribers to an SNS topic can include a wide range of endpoints, such as email addresses, mobile phone numbers, Amazon SQS (Simple Queue Service) queues, AWS Lambda functions, and HTTP/HTTPS endpoints. This flexibility enables you to choose the most appropriate method for delivering messages to your recipients.
  3. Push Notifications: Amazon SNS provides a mechanism for sending push notifications to mobile devices, such as smartphones and tablets, through platforms like Apple iOS, Google Android, and Amazon Fire OS.
  4. Fanout Architecture: SNS supports fanout architecture, which means a single message can be delivered to multiple endpoints or subscribers simultaneously. This makes it easy to broadcast messages to a large number of recipients without the need to manage individual delivery mechanisms.
  5. Topic Hierarchies: You can organize your topics hierarchically, allowing for structured communication patterns and better management of large numbers of topics.
  6. Cross-Region Replication: SNS supports cross-region replication, which allows you to create topics in different AWS regions and replicate messages between them for improved availability and disaster recovery.

Tasks

Task 1)Create a CloudWatch alarm that monitors your billing and send an email to you when a it reaches $2.

Open AWS console > Click on Billing Dashboard

After Opening Billing Dashboard > Click on Billing Preferences

Under Invoice delivery preferences > Click on edit > Checkbox for PDF invoices delivered by email > Click on Update > Under Alert preferences > Checkbox for Receive AWS Free Tier alerts and Receive CloudWatch billing alerts.

Now let us go ahead and create the CloudWatch alarm.

Go to AWS Management Console > Search & Navigate to Cloudwatch Service > In the left navigation pane, click on Alarms > Click on Create Alarm.

Select Billing

Go to Graphed Metrics > Set Statistic as Maximum > For Period choose 6 hours

Under Conditions > Select Threshold type as Static > Select Whenever EstimatedCharges is… as Greater > Give 2 USD for than… > Click on Next.

Under Notifications:

For the Alarm state trigger select In alarm > Create New Topic > Create a topic with your mail ID and topic name.

Click on Next.

2) Delete your billing Alarm that you created now.

Go to AWS Management Console > Navigate to the CloudWatch service > In the left navigation pane, click on “Alarms” > Select the Billing Alarm you want to delete > Click on Actions > And choose Delete.

You can see that the Alarm was deleted successfully.

--

--

Radheya Zunjur
Radheya Zunjur

Written by Radheya Zunjur

Database Engineer At Harbinger | DevOps | Cloud Ops | Technical Writer

No responses yet