Set up CloudWatch alarms and SNS topic in AWS

Set up CloudWatch alarms and SNS topic in AWS

Amazon Web Services (AWS) provides a plethora of resources, and as you deploy more services, it's crucial to monitor your expenses. AWS CloudWatch allows you to set up billing alerts, ensuring that you're always aware of your costs.

AWS CloudWatch provides a robust monitoring solution, allowing users to watch over their AWS resources and applications, and to react to any changes in their environment. One of the most overlooked but essential use cases is monitoring AWS costs and sending notifications to stay within budget. In this blog, we’ll walk through how to set up CloudWatch alarms for billing and use Simple Notification Service (SNS) for notifications.

Why Monitor Billing?

AWS offers a plethora of services, each with its own pricing structure. As usage increases or services change, costs can quickly escalate. It's crucial to set up proactive monitoring to ensure you’re aware of any unexpected spikes in spending.

Step-by-Step Guide to Set Up CloudWatch Alarms for Billing

Step 1: Enable Billing Alerts

Before setting up CloudWatch alarms, ensure that Billing Alerts are activated:

  1. Sign in to the AWS Management Console.

  2. Navigate to Billing.

  3. In the left navigation pane, select Billing Preferences.

  4. Check the box for Receive Billing Alerts.

  5. Update preferences.

Step 2: Create an SNS Topic

  1. Navigate to the SNS (Simple Notification Service) dashboard.

  2. Click Create topic.

  3. Choose a name and display the name for your topic. For instance, name it “BillingAlerts”.

  4. Click Create topic - Type Standard

Once created, you can add subscribers to this topic. These subscribers will be notified when the alarm is triggered:

  1. Click on the created topic.

  2. Select Create subscription.

  3. Choose the protocol (e.g., Email) and provide an endpoint (the email address where the notification will be sent).

  4. Confirm the subscription through the link sent to the email.

Step 3: Create a CloudWatch Alarm for Billing

  1. Navigate to the CloudWatch dashboard.

  2. In the left navigation pane, click on Alarm and then Billing -> Create alarm.

  3. Choose the Billing metric namespace.

  4. Define your desired threshold. For instance, if you want to be alerted when your monthly AWS bill exceeds $1, set that as your threshold.

  5. In the Actions section, set the state to “In Alarm” and choose the SNS topic created in Step 2.

    Keeping other things default and click on Next

  6. Set the alarm name, description, and other specifics as required.

  7. Click Create Alarm.

You're all set! Now, whenever your AWS costs exceed the threshold, CloudWatch will trigger the alarm, and a notification will be sent to the subscribed email address.

Conclusion

Proactively monitoring your AWS billing can save you from unexpected costs. CloudWatch alarms, combined with SNS notifications, offers a streamlined way to keep you informed about your AWS spending. Remember, it's always better to prevent unexpected expenses than to react to them!

Thanks for reading 🙏😀