Table of contents
Hey learners, you have been using aws services atleast for last 45 days. Have you ever wondered what happen if for any service is charging you bill continously and you don't know till you loose all your pocket money ?
Hahahaha😁, Well! we, as a responsible community ,always try to make it under free tier , but it's good to know and setup something , which will inform you whenever bill touches a Threshold.
What is Amazon CloudWatch?
Amazon CloudWatch is a monitoring and observability service provided by Amazon Web Services (AWS). It allows you to collect and track metrics, collect and monitor log files, set alarms, and automatically react to changes in your AWS resources and applications. It allows you to implement alarming actions for starting, stopping, and terminating the EC2 instance if a criterion is met. Apart from that, developers can also create alarms for initiating Amazon SNS and Amazon EC2 auto-scaling actions for you.
The CloudWatch can also be used to detect anomalous behavior in the environments, set warnings and alarms, visualize logs and metrics side by side, take automated actions, and troubleshoot issues.
Here are some key features of Amazon CloudWatch:
Metrics and Monitoring: CloudWatch enables you to collect and monitor metrics from various AWS resources such as EC2 instances, RDS databases, S3 buckets, Lambda functions, and more. These metrics can be visualized in graphs, and you can set up alarms based on certain thresholds to trigger notifications or automated actions.
Logs Monitoring: CloudWatch Logs allows you to collect, monitor, and store log files from your applications, operating systems, and AWS services. You can centralize logs from multiple sources and search, filter, and analyze them in real-time. CloudWatch Logs Insights provides a powerful query language to extract meaningful information from log data.
Dashboards: CloudWatch Dashboards allow you to create customizable dashboards to visualize and monitor your metrics and logs. You can create charts, graphs, and widgets to display the desired set of metrics and logs on a single page, providing a consolidated view of your application's health and performance.
Alarms: CloudWatch Alarms allow you to set thresholds on metrics and trigger actions when those thresholds are breached. You can configure alarms to send notifications via Amazon SNS, auto-scale your resources, or execute AWS Lambda functions. Alarms help you proactively respond to and resolve issues before they impact your applications.
Events and Event-Based Automation: CloudWatch Events enables you to monitor and respond to events in your AWS resources. You can define rules to match events and take actions based on those rules. For example, you can trigger a Lambda function when an EC2 instance is launched or stop an instance at a specific time using scheduled events.
Integration with AWS Services: CloudWatch integrates with various AWS services, allowing you to gain insights and monitor the health of your resources. For example, you can monitor AWS Lambda function invocations, track API activity in Amazon API Gateway, and analyze load balancer metrics in Amazon Elastic Load Balancing.
How Amazon CloudWatch Works
At first Amazon Cloud watch will configured to the resource that you want to monitor from there the agents that are configured will be used to collect the logs from the resources the service may be run on-premises or AWS. Cloudwatch performs real-time analysis based on the logs that have been received.
Benefits of Amazon Cloudwatch
Ease of real-time processing of CloudWatch log data and ease of streaming log data to Amazon Elasticsearch
Simple system integration using AWS EC2 instances
Continuity and dependability
simplicity of use
effective AWS resource monitoring
allows for the alerting of anomalies found using Amazon SNS
What is Amazon SNS?
Amazon SNS (Simple Notification Service) is a fully managed messaging service provided by Amazon Web Services (AWS). It is a web service that automates the process of sending notifications to the subscribers attached to it.
SNS provides this service to both application-to-person and application-to-application. It uses the publishers/subscribers paradigm for the push and delivery of messages. It sends the notifications through SMS or email to an Amazon Simple Queue Service (SQS), AWS lambda functions, or an HTTP endpoint.
How Does Amazon (SNS) Work?
When the CPU utilization of an instance goes above 80%, the AWS cloudwatch alarm is triggered. This cloudwatch alarm activates the SNS topic hence notifying the subscribers about the high CPU utilization of the instance. SNS service has a topic that has a unique name. It acts as a logical access point and a communication channel between publishers and subscribers.
Benefits of Amazon SNS:
Modernize and decouple your applications: Amazon SNS enables you to modernize your applications and decouple them into smaller, independent components that are easier to develop, deploy, and maintain. Leveraging a pub/sub event-driven architecture for your application improves performance, reliability, and allows each component to scale independently.
Automatically scale your workload: Amazon SNS leverages the proven Amazon Web Services cloud to dynamically scale with your application. The service is designed to handle high-throughput, bursty traffic patterns and enables you to send millions of messages per second.
Simplify your architecture with Message Filtering: Amazon SNS helps you simplify your pub/sub messaging architecture by offloading the message filtering logic from your subscriber systems, and message routing logic from your publisher systems.
Task 1:
Create a CloudWatch alarm that monitors your billing and send an email to you when a it reaches $2.
🔹step1: Log in to the AWS management console and go to the cloudwatch section.
🔹step2: Find the 'Alarms' section and click on 'Create Alarm.'
🔹step3: Go to the billing and cost management
- Then go to the preferences and click on billing preference and edit it.
🔹step4: Click on Metric and Choose 'Billing' as your metric.
- Then go to alert preferences and select Receive Cloudwatch billing alerts and update
🔹step5: In Browse, choose Billing, and then choose Total Estimated Charge
🔹step6: Add the condition for the alarm
For the Threshold type, choose Static.
For Whenever EstimatedCharges is, choose Greater.
define a threshold value that triggers your alarm. here threshold value is 2$.
🔹step7: Check the Additional Configuration,
🔹step8: Create the email notification.
It should be the same. Under Notification, specify an Amazon SNS topic to be notified when your alarm is in the ALARM state.
In the "Actions" section, click on "New Topic" and select "Create new ". Choose the action type as "Send notification to an SNS topic" and click on "Create new topic"
🔹step9: Successfully created the alarm
🔹step10: Click on View SNS Subscription. Select the checkbox and click on Request Confirmation.
By doing this, you will receive an email to your given email id.
Click on Confirm subscription from your mobile device. The status will change to Confirmed.
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 and Click on Actions to Delete.
You can see that the Alarm was deleted successfully.
Thank you for 📖reading my blog, 👍Like it and share it 🔄 with your friends.
Happy learning😊😊