How to Monitor Your AWS Billing and Get Alerts Using CloudWatch and SNS 🚨
Learn how to use CloudWatch and SNS to create a CloudWatch alarm that monitors your billing and sends an email to you when it reaches $2.
Are you a DevOps learner who wants to keep track of your AWS billing and get notified when it exceeds a certain threshold? If yes, then this blog post is for you.
In this post, I’ll explain what CloudWatch and SNS are and how to use them to create a CloudWatch alarm that monitors your billing and sends an email to you when it reaches $2.
By the end of this post, you’ll be able to:
Understand what CloudWatch and SNS are and how they work together
Create a CloudWatch alarm that monitors your billing
Create an SNS topic and subscribe your email address to it
Configure the CloudWatch alarm to send notifications to the SNS topic
Delete the CloudWatch alarm and the SNS topic
Let’s get started!
What is Amazon CloudWatch?
Amazon CloudWatch is a service that 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. For example, you can monitor the CPU utilization, disk reads and writes, network traffic, and request count of your EC2 instances. You can also monitor the billing metrics for your AWS account, such as the estimated charges, the total cost, and the cost by service.
CloudWatch also allows you to set alarms, which are rules that trigger actions when a metric crosses a specified threshold. For example, you can set an alarm that sends you an email when your EC2 CPU utilization exceeds 80%. You can also set an alarm that stops or terminates your EC2 instance when your billing exceeds a certain amount.
To send notifications to yourself or other recipients, you need to use another AWS service called Amazon Simple Notification Service (SNS).
What is Amazon SNS?
Amazon Simple Notification Service (SNS) is a notification service that provides a low-cost infrastructure for mass delivery of messages, predominantly to mobile users. You can use SNS to send SMS messages, push notifications, or emails to your users or subscribers. You can also use SNS to send messages to other AWS services, such as Lambda functions, SQS queues, or HTTP endpoints.
SNS works with the concept of topics and subscriptions. A topic is a logical access point and a communication channel for sending and receiving messages. A subscription is an endpoint that receives messages from a topic. For example, you can create a topic called “BillingAlerts” and subscribe your email address to it. Then, you can send messages to the topic, and they will be delivered to your email address.
You can also use SNS to receive notifications from CloudWatch alarms. You can configure your CloudWatch alarm to send messages to an SNS topic, and then subscribe your email address or other endpoints to the topic. This way, you can get alerts when your CloudWatch alarm is triggered.
Now that you know what CloudWatch and SNS are, let’s see how to use them to monitor your AWS billing and get alerts.
How to Create a CloudWatch Alarm that Monitors Your Billing
To create a CloudWatch alarm that monitors your billing, you need to follow these steps:
Step 1: Navigate to the CloudWatch Console
Sign in to your AWS account and open the AWS Management Console.
In the search bar at the top of the console, type "CloudWatch" and select "CloudWatch" from the search results.
Step 2: Access Billing Alarms
In the CloudWatch console's left navigation pane, under "Alarms," choose "Billing".
Step 3: Create New Alarm
Click on the "Create alarm" button to initiate the alarm creation process.
Step 4: Specify Metric
A default selected metric will appear with the namespace AWS/Billing. Provide a descriptive name for the selected metric, such as "EstimatedCharges." You can edit the metric.
Step 5: Specify Alarm Conditions
Select the "Static" threshold type.
Select "Greater/Equal" for "Whenever EstimatedCharges is".
Set the "Threshold" value to the desired threshold for triggering the alarm, such as "2 USD."
Step 6: Configure Actions
Under "Notification," choose "In alarm" for "alarm state trigger".
Select an existing SNS topic from the drop-down menu or create a new topic by clicking on "Create new topic."
If creating a new topic, provide a name and a display name for the topic, such as "BillingAlertsTopic."
Subscribe your email address or other endpoints to the topic by clicking on "Create subscription" and entering the necessary details.
Confirm the subscription by following the instructions in the email or message sent to you.
Step 7: Name and description
- Provide a descriptive name for the alarm, such as "BillingAlarm."
Step 8: Review and Create Alarm
Review the alarm configuration summary to ensure all settings are accurate.
Click on the "Create alarm" button to finalize the alarm creation process.
You have successfully created a CloudWatch alarm that monitors your billing and sends an email to you when it reaches $2. You can view your alarm status and history in the CloudWatch console, under Alarms. You can also modify or delete your alarm at any time.
Note: To address the 'Insufficient Data' state, you can wait for CloudWatch to collect more data. Once a sufficient number of data points are available, CloudWatch will begin evaluating the alarm condition, and the state will change accordingly.
How to Delete the CloudWatch Alarm and the SNS Topic
In this section, I’ll show you how to delete the CloudWatch alarm and the SNS topic that you created in the previous sections. You may want to do this if you don’t need them anymore, or if you want to avoid getting charged for them.
Step 1: Delete the CloudWatch Alarm
To delete the CloudWatch alarm, follow these steps:
Go to the CloudWatch console and select Alarms from the left navigation pane.
Find the alarm that you created, which should have the name BillingAlarm. Select it and click on Actions and then Delete.
Confirm the deletion by clicking on Delete again.
Step 2: Delete the SNS Topic
To delete the SNS topic, follow these steps:
Go to the SNS console and select Topics from the left navigation pane.
Find the topic that you created, which should have the name BillingTopic. Select it and click on Delete
Confirm the deletion by typing Delete me in the textbox.
In this blog post, you learned how to monitor your AWS billing and get alerts using CloudWatch and SNS. You learned what CloudWatch and SNS are and how to use them to create a CloudWatch alarm that monitors your billing and sends an email to you when it reaches $2. You also learned how to delete the alarm and the topic if you don’t need them anymore.
I hope you found this blog post useful and informative. If you have any questions or feedback, please leave a comment below. If you want to learn more about CloudWatch and SNS, you can check out the following resources:
Thank you for reading and happy learning! 🙏
Did you find this article valuable?
Support Ajit Fawade by becoming a sponsor. Any amount is appreciated!