Search⌘ K
AI Features

Demo: CloudWatch Alarm

Explore how to create CloudWatch alarms for DynamoDB both from the AWS CLI and console, configure SNS notifications, and trigger alarms by inserting data to monitor DynamoDB write activity effectively.

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:

Shell
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.

Shell
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 ...