Set up CloudWatch alarms and SNS topic in AWS
#90 Days of DevOps Challenge - Day 46
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.
Advantages of using Amazon CloudWatch
Amazon CloudWatch offers several advantages for monitoring and managing resources in the AWS (Amazon Web Services) cloud environment. Some of the key advantages of using Amazon CloudWatch are:
Centralized Monitoring: CloudWatch provides a centralized platform for monitoring various AWS resources such as EC2 instances, databases, load balancers, and more. It allows you to collect and track metrics, logs, and events from these resources, providing a comprehensive view of your applications and infrastructure.
Scalability and Flexibility: CloudWatch scales effortlessly with your infrastructure. It can handle a vast amount of monitoring data and can easily accommodate dynamic workloads, automatically adjusting to changes in resource usage and demand.
Real-time Monitoring and Alerting: CloudWatch provides real-time monitoring capabilities, allowing you to track metrics and view graphs and statistics in near real-time. It also enables you to set up alarms based on thresholds and send notifications via various channels (e.g., email, SMS, AWS Simple Notification Service) to alert you when specific conditions are met or when there are deviations from expected behavior.
Comprehensive Metrics and Logs: CloudWatch provides a rich set of pre-defined metrics for monitoring AWS services. Additionally, it supports custom metrics, enabling you to collect and monitor application-specific data. You can also collect and analyze logs from various AWS services using CloudWatch Logs, gaining insights into system behavior, troubleshooting issues, and detecting trends.
Integration with AWS Services: CloudWatch seamlessly integrates with other AWS services, such as Amazon EC2, Amazon RDS (Relational Database Service), Amazon S3 (Simple Storage Service), and AWS Lambda. This integration allows you to monitor and gain insights into the performance and health of these services, optimizing their usage and ensuring they meet your requirements.
Automation and Auto Scaling: CloudWatch integrates with AWS Auto Scaling, allowing you to define scaling policies based on metrics. This enables you to automatically adjust the capacity of your resources in response to changes in demand, ensuring optimal performance and cost-efficiency.
Powerful Analysis and Insights: CloudWatch provides advanced features for analyzing and visualizing monitoring data. With CloudWatch Logs Insights and CloudWatch Contributor Insights, you can perform ad-hoc queries, filter and aggregate log data, and gain valuable insights into the behavior of your systems and applications.
Cost Optimization: By utilizing CloudWatch, you can optimize costs by monitoring resource utilization, identifying underutilized resources, and making informed decisions about scaling or right-sizing your infrastructure. You can also take advantage of CloudWatch's detailed billing and cost allocation reports to gain visibility into your AWS costs.
Overall, Amazon CloudWatch offers a robust and feature-rich monitoring solution for AWS, empowering you to gain deep visibility into your cloud resources, ensure high availability, troubleshoot issues, and optimize performance and costs.
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.
Advantages of using Amazon SNS
Using Amazon SNS (Simple Notification Service) offers several advantages for building scalable and reliable applications. Some of the key advantages of using Amazon SNS are:
Pub/Sub Messaging Model:-Amazon SNS follows a publish/subscribe messaging model, allowing you to decouple your application components. Publishers send messages to topics, and subscribers receive messages from those topics. This model enables asynchronous communication between components, facilitating scalability and loose coupling.
Reliable Message Delivery:-Amazon SNS ensures reliable message delivery by automatically retrying message delivery if a failure occurs. It also supports configurable delivery policies, including the ability to set message retention periods and specify the maximum message size. This ensures that your messages are reliably delivered to subscribers, even in the face of temporary failures or intermittent connectivity issues.
Multiple Communication Protocols:- Amazon SNS supports multiple communication protocols, including HTTP/HTTPS, email, SMS (text messages), mobile push notifications (Apple Push Notification Service, Google Cloud Messaging, etc.), and Amazon Simple Queue Service (SQS). This allows you to choose the most appropriate protocol for your application's needs and reach your subscribers through their preferred channels.
Scalability and High Throughput:- Amazon SNS is designed to handle high message throughput, allowing you to send messages to a large number of subscribers simultaneously. It automatically scales to accommodate the volume of messages, ensuring reliable and timely delivery, even during periods of high demand.
Cross-Platform and Multi-Region Support:- Amazon SNS supports a wide range of platforms and devices, making it suitable for building applications that target multiple platforms such as web, mobile, and IoT. It also operates across multiple AWS regions, ensuring high availability and fault tolerance for message delivery.
Flexible Message Filtering:- Amazon SNS provides flexible message filtering capabilities. You can use filter policies to selectively deliver messages to subscribers based on attributes contained in the messages. This allows you to create more targeted and personalized messaging experiences for your subscribers.
Easy Integration with AWS Services:-Amazon SNS seamlessly integrates with various AWS services, such as AWS Lambda, Amazon SQS, Amazon EC2 Auto Scaling, and more. This integration enables you to easily trigger actions or notifications based on events occurring in these services, providing a powerful mechanism for building event-driven architectures.
Monitoring and Visibility:- Amazon SNS integrates with Amazon CloudWatch, allowing you to monitor and gain insights into your message-based workflows. You can track message throughput, monitor error rates, set alarms, and use CloudWatch metrics and logs to analyze the performance and behavior of your SNS topics.
Cost-Effective Solution:-Amazon SNS offers a pay-as-you-go pricing model, where you only pay for the messages you send and the additional features you use. This makes it a cost-effective solution, especially when compared to building and maintaining your own messaging infrastructure.
Overall, Amazon SNS provides a flexible, scalable, and reliable messaging service, enabling you to build loosely coupled and highly scalable applications. It simplifies the implementation of pub/sub messaging patterns, facilitates cross-platform communication, and integrates seamlessly with other AWS services, making it a valuable tool for building modern, event-driven architectures.
Task :
Create a CloudWatch alarm that monitors your billing and sends an email to you when it reaches $2.
Delete the billing Alarm that you created now.
Step 1:- First we need to go to Aws console and need to click on Billing Dashboard -> choose Billing Preferences
Step 2:- We need to make sure all Billing Alerts & Save preferences are activated
Step 3:- Now we need to create cloud watch bill alarm so that case first we need to go to cloud watch and then click on in alarm -> create alarm
Step 4 :- Now we need to choose select metric
In select metric need to choose Billing
need to select the EstimatedCharges metric
select tick EstimatedCharges metric -> Select metric
select Statistic, need to choose Maximum & for Period, choose 6 hours
now as per the requirement we have selected an amount is 2$ so when bill is crossed 2$ it will send an email
Step 5:- Now we need to create SNS Topic so it can send an email when it triggered and need to click on next
Now we need to select the name and click on next
need to preview the changes and click on create alarm
Now we can see alarm is created
and we can see the expected output
Step 6:- Now we need to delete the alarm which we have created
Thank you for reading!! I hope you find this article helpful!!
if any queries or corrections to be done to this blog please let me know.
Happy Learning!!
Saikat Mukherjee