dynamo-db
  1. dynamo-db-setting-up-alarms-and-notifications

Setting Up Alarms and Notifications in DynamoDB using CloudWatch

DynamoDB is a managed NoSQL database that provides continuous backups, point-in-time recovery, automatic scaling, and global replication features. Amazon CloudWatch is a monitoring and management service that provides data and actionable insights for AWS resources. In this tutorial, we will learn how to set up alarms and notifications in DynamoDB using CloudWatch.

Syntax

aws cloudwatch put-metric-alarm --alarm-name <Name> --alarm-description <Description> --metric-name <Metric-Name> --namespace <Namespace> --statistic <Statistic> --period <Period-Seconds> --threshold <Threshold> --comparison-operator <Operator> --dimensions Name=<Dimension-Name>,Value=<Dimension-Value> --evaluation-periods <Number> --actions-enabled --alarm-actions <SNS-Topic-ARN>

Example

Let's take an example of the ConsumedReadCapacityUnits metric we want to monitor. We will create a CloudWatch alarm that will trigger a notification when the ConsumedReadCapacityUnits metric exceeds a specified threshold value.

First, we need to create a SNS topic to send the notifications. Then, we can create the CloudWatch alarm and configure it to send notifications to the SNS topic.

aws sns create-topic --name dynamodb-read-capacity-alert

aws cloudwatch put-metric-alarm \
--alarm-name DDB-Read-Capacity-Alarm \
--alarm-description "Alarm when read capacity exceeds 100" \
--metric-name ConsumedReadCapacityUnits \
--namespace AWS/DynamoDB \
--statistic Sum --period 300 --threshold 100 \
--comparison-operator GreaterThanThreshold \
--dimensions Name=TableName,Value=MyTable \
--evaluation-periods 2 \
--actions-enabled \
--alarm-actions arn:aws:sns:us-east-2:01234567890:dynamodb-read-capacity-alert

In the above example, we created an SNS topic named dynamodb-read-capacity-alert, which will be used to send email notifications when the alarm is triggered. Then, we created a CloudWatch alarm that will send notifications to the dynamodb-read-capacity-alert SNS topic. The alarm will be triggered when the ConsumedReadCapacityUnits metric exceeds 100 for a period of 10 minutes (300 seconds) or across two consecutive periods.

Output

Once the alarm is triggered, an email notification will be sent to the email address(s) subscribed to the SNS topic mentioned in --alarm-actions field.

Explanation

In the above syntax, put-metric-alarm command is used to create an alarm. The command takes several parameters:

  • --alarm-name: The name of the alarm.
  • --alarm-description: A description of the alarm.
  • --metric-name: The name of the metric to monitor.
  • --namespace: The namespace of the metric.
  • --statistic: The statistic to apply to the metric.
  • --period: The period over which the statistic is applied.
  • --threshold: The threshold value at which to trigger the alarm.
  • --comparison-operator: The comparison operator used to compare the metric value with the threshold.
  • --dimensions: The dimensions to apply to the metric.
  • --evaluation-periods: The number of consecutive periods over which the condition must be met to trigger the alarm.
  • --actions-enabled: Whether or not actions should be enabled for the alarm.
  • --alarm-actions: The Amazon Resource Number (ARN) of the SNS topic to which to send notifications when the alarm is triggered.

Use

Setting up alarms and notifications in DynamoDB using CloudWatch can help us monitor the performance and usage of our DynamoDB tables and get notified proactively if an alarm is triggered, preventing any potential performance issues that may impact our applications.

Important Points

  • Alarms are based on individual metrics, and you can create multiple alarms per metric.
  • CloudWatch only retains data for a maximum of 15 months.
  • When creating CloudWatch alarms, make sure the metric being watched reflects the desired performance aspects of DynamoDB table.
  • Both email and SMS notifications can be sent to the specified SNS topic.

Summary

In this tutorial, we learned how to set up alarms and notifications in DynamoDB using CloudWatch. We saw how to create a CloudWatch alarm and configure it to send notifications to an SNS topic. Understanding how to monitor and receive notifications for our DynamoDB databases can help us be proactive in troubleshooting and optimize our database performance.

Published on: