Day-46: Set up CloudWatch alarms and SNS topic in AWS (Jan 11, 2024)

Day-46: Set up CloudWatch alarms and SNS topic in AWS (Jan 11, 2024)

ยท

5 min read

๐Ÿ™ Introduction:

In this blog, we will set up CloudWatch alarms and configure an SNS. These powerful tools will help us monitor and receive notifications about critical events within our AWS environment

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 the 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 on 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.

๐ŸŽฏTask: 1

Create a CloudWatch alarm that monitors your billing and sends an email to you when it reaches $2.

To enable the monitoring of estimated charges

  • In the navigation pane, choose Billing Preferences.

  • By Alert preferences choose Edit, Choose Receive CloudWatch Billing Alerts, and Choose Save preferences.

Creating a billing alarm

  • In the navigation pane, choose Alarms, and then choose All alarms.

  • Choose to Create Alarm select metric

  • In Browse, choose Billing, and then choose Total Estimated Charge

  • Select the box for the EstimatedCharges metric, and then choose Select metric

For Statistic, choose Maximum For Period, choose 6 hours

  • For the Threshold type, choose Static.

  • For Whenever EstimatedCharges is choose Greater

  • For then define the value that you want to cause your alarm to trigger

  • Under Notification, ensure that In alarm is selected. Then specify an Amazon SNS topic to be notified when your alarm is in the ALARM state. The Amazon SNS topic can include your email address so that you receive an email when the billing amount crosses the threshold that you specified.

  • You can select an existing Amazon SNS topic, create a new Amazon SNS topic, or use a topic ARN to notify another account. If you want your alarm to send multiple notifications for the same alarm state or for different alarm states, choose Add Notification.

  • Under Name and Description, enter a name for your alarm

  • Under Preview and create, make sure that your configuration is correct, and then choose Create alarm.

Delete your billing Alarm that you created now.

Select the checkbox of the alarm you want to delete. Navigate and click on Actions, Under it, click on Delete.

ย