Setup integration: Amazon CloudWatch Alarm

You need to setup an AWS SNS HTTPS endpoint for this integration!

Amazon CloudWatch provides metrics that you can observe with alarms. Once a metric reaches a threshold, the alarm can trigger an action.

I will show you how you can monitor your AWS bill. If your bill goes above a certain threshold, an event is sent to marbot that triggers an alert. You can not only monitor your AWS bill in CloudWatch. CloudWatch provides much more!

Allowing AWS to send messages to your topic

  1. Visit https://console.aws.amazon.com/sns/?region=us-east-1
  2. Click on the Topics link on the left
  3. Select the topic that you created for marbot
  4. Click on the Actions button, where you click on the Edit topic policy link.
    Edit SNS topic policy
  5. Select the Advanced view tab

If this is the first time you edit the SNS topic policy, you should see a default entry like this:

{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
[...TRUNCATED...]
}
]
}

If you see the default entry, go to the next step. Otherwise, replace it with this policy:

{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"SNS:GetTopicAttributes",
"SNS:SetTopicAttributes",
"SNS:AddPermission",
"SNS:RemovePermission",
"SNS:DeleteTopic",
"SNS:Subscribe",
"SNS:ListSubscriptionsByTopic",
"SNS:Publish",
"SNS:Receive"
],
"Resource": "ARN",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "ACCOUNT_ID"
}
}
}
]
}
  1. Replace ARN with your SNS topic ARN that you created for marbot.
  2. Replace ACCOUNT_ID with your AWS Account ID.
  3. Click on the Update policy button to save the policy.

Save SNS topic policy

Now, AWS is allowed to send messages to your topic.

Monitoring your AWS bill with a CloudWatch Alarm

  1. Visit https://console.aws.amazon.com/cloudwatch/home?region=us-east-1
  2. Ensure that you are in the N. Virgina region
  3. Click on the Alarm link on the left
  4. Click on the Create Alarm button
  5. Click on the Total Estimated Charge metric under Billing Metrics
  6. Select the only line

You should now see the following screen:

Billing Metric

  1. Click on the Next button on the bottom
  2. Set a Name and a Description for the alarm
  3. Set the threshold to $0 to ensure that the alarm is triggered (for test purposes only, you can change this later)
  4. In the actions section at the bottom, set Send notification to the SNS topic you created, e.g. marbot.
  5. Save by clicking the Create alarm button.

Billing Metric

Sample Alert

Within a minute you should receive an alert in Slack:

Billing Alert via CloudWatch Alarm