AWS Databases: New Auto Scaling for Amazon DynamoDB

Tech Blog / AWS Databases: New Auto Scaling for Amazon DynamoDB
AWS Databases: New Auto Scaling for Amazon DynamoDB

Amazon DynamoDB is a very popular NoSQL database service. Among AWS databases, the Flux7 AWS consultants like DynamoDB for its fast, reliable performance, especially for real time apps where we need faster access of data e.g. commerce, big data analytics, and IoT applications. Moreover, as a managed service, AWS takes care of the administrative burden (e.g. hardware provisioning, setup and configuration, replication, software patching, etc.) for you. While this database is well-loved, one feature that has been in high-demand–and we are happy to say was just released by AWS–is Auto Scaling for DynamoDB. We are really excited to see AWS deliver Auto Scaling to DynamoDB customers as it will make administration and managing capacity of data even easier, will help maximize availability for applications, all of which will positively impact cost savings.

This was a much-requested feature because without auto scaling, you had to find an alternate solution which involved the use of lambda function(s). The work around involved a lambda function where, if the read/write throughput reached capacity, the lambda function triggered a CloudWatch alarm. This would trigger a lambda function which tuned the provisioned capacity of the DynamoDB table to meet the throughput demand. Now that same CloudWatch alarm can trigger the auto scaling feature built into DynamoDB which saves us administrative work, removing room for potential error and streamlining the process.

Application auto scaling is used to scale up/down DynamoDB throughput. Enabling auto scaling for DynamoDB involves the creation of three additional resources:

 

  1. An IAM Role which gives specific permissions to the application auto scaling service.
  2. A scalable target
  3. A scaling policy

As strong supporters of AWS automation, we created a simple CloudFormation template to enable auto scaling for DynamoDB. Here is a snippet of the template which creates a scalable target and a scaling policy to scale DynamoDB read throughput.

DynamoDBAutoscalingRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
            - sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - application-autoscaling.amazonaws.com
      Path: /
      Policies:
        - PolicyName: DynamoDBAutoscaling
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Action:
                  - "dynamodb:DescribeTable"
                  - "dynamodb:UpdateTable"
                  - "cloudwatch:PutMetricAlarm"
                  - "cloudwatch:DescribeAlarms"
                  - "cloudwatch:DeleteAlarms"
                Effect: "Allow"
                Resource: "*"

DynamoDBReadScalableTarget:
   Type: AWS::ApplicationAutoScaling::ScalableTarget
   Properties:
     ScalableDimension: 'dynamodb:table:ReadCapacityUnits'
     MinCapacity: !Ref ReadCapacityUnitsMin
     MaxCapacity: !Ref ReadCapacityUnitsMax
     ResourceId: !Sub table/${myDynamoDBTable}
     RoleARN: !GetAtt DynamoDBAutoscalingRole.Arn
     ServiceNamespace: dynamodb

DynamoDBReadScalingPolicy:
    Type: "AWS::ApplicationAutoScaling::ScalingPolicy"
    Properties:
      PolicyName: Read Scaling Policy
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref DynamoDBReadScalableTarget
      TargetTrackingScalingPolicyConfiguration:
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBReadCapacityUtilization
        ScaleOutCooldown: 60
        ScaleInCooldown: 60
        TargetValue: 30.0

Post Date: 09/19/2017

default blog image

About the Author:

Flux7 Labs

This was originally written by Flux7 Inc., which became part of NTT DATA Services as of December 30, 2019

X