We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

CloudWatch Alarms

Our metrics and logs are being sent to AWS, but we have to check them manually to find out if something is wrong. Not ideal...

CloudWatch Alarms lets us set up automatic "actions" to be taken when certain criteria are met. For example:

  • Our service is in an Auto Scaling Group of 1-10 servers based on CPU usage, and we just hit 10!
  • We have a service emitting a high number of 5XX errors!
  • One of our servers is at 95% disk usage!

Let's create a simple alarm that triggers when our server goes above 20% CPU usage. When triggered, it will send a notification via SNS (Simple Notification Service) to a given email address.

Assignment

Create a CloudWatch alarm that trigger an email when CPU usage exceeds 20%.

Cost check: CloudWatch Alarms are free for the first 10 alarms. SNS notifications cost $0.50 per 100,000 requests.

    1. When you first create an alarm, it may show Insufficient data; this just means it hasn't gathered enough data points yet to make a decision. This will resolve itself after a few periods.

    1. ssh patientping
      yes > /dev/null
      

If that all worked, run and submit the CLI tests.

Tip

Want to use the AWS CLI instead? Here's the command structure:

# Create SNS topic
aws sns create-topic --name TOPIC-NAME

# Subscribe email address to topic
aws sns subscribe --topic-arn TOPIC-ARN --protocol email --notification-endpoint EMAIL-ADDRESS

# Create alarm
aws cloudwatch put-metric-alarm --alarm-name ALARM-NAME --metric-name METRIC-NAME --namespace NAMESPACE --statistic Average --period PERIOD-SECONDS --threshold THRESHOLD --comparison-operator GreaterThanThreshold --evaluation-periods 1 --alarm-actions TOPIC-ARN