Demo: CloudWatch Alarm

Practice working with CloudWatch alarms.

Creating an Alarm using the AWS CLI

Let's create an alarm and witness CloudWatch in action. We'll start by creating an SNS topic using this command:

Press + to interact
aws sns create-topic --name WriteAlarm

An SNS topic will be created. Copy and save the TopicArn returned as the output, as it will be used later.

Now we'll use this command to subscribe to this topic and create the alarm. Before running this command, replace <TopicArn> in lines 1 and 11 with the ARN of the topic saved earlier and <EmailAddress> in line 2 with an email address.

Press + to interact
aws sns subscribe --topic-arn <TopicArn> --protocol email \
--notification-endpoint <EmailAddress> \
&& aws cloudwatch put-metric-alarm --alarm-name MedicineTableWriteAlarm \
--metric-name ConsumedWriteCapacityUnits \
--namespace AWS/DynamoDB \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--threshold 1 \
--comparison-operator GreaterThanOrEqualToThreshold \
--alarm-actions <TopicArn> \
--dimensions "Name=TableName,Value=Medicines"

The subscribe command in line 1 will create a subscription. We will get an email to confirm our SNS subscription. We will click “Confirm ...