How can you manage write capacity for a global secondary index based on an autoscaled dynamodb table?

Viewed 1506

Global secondary indexes have capacity provisioned separately from the tables where they are applied. If insufficient write capacity is allocated for the GSI, then writes to the table are throttled. Therefore, if autoscaling for writes to the table is triggered, then one should expect that the write capacity of the GSI would need to be managed in response.

Autoscaling for table reads/writes can be configured through the AWS Management Console, via the CLI or using CloudFormation. The documentation posts sample JSON/YAML to accomplish this for table provisioning. However, when I attempt to create a new GSI on an autoscaled table, I see no options to mirror the table's settings. Nor can I find CLI or CloudFormation examples in the documentation on how to explicitly deal with indexes and auto-scaling.

So how do you manage write capacity for a GSI? Is my understanding of how things should work correct? Or does AWS "do the right thing" (in their opinion, anyway) and autoscale the GSI in parallel with the underlying table?

2 Answers

It is now possible to define the secondary index as an autoscaling target. It's nearly the same compared to the normal table. You just have to change the resourceId and ScalableDimension of the AWS::ApplicationAutoScaling::ScalableTarget.

  SecIndexWriteCapacity:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      MaxCapacity: 1000
      MinCapacity: 15
      ResourceId: !Sub "table/${MY_MAIN_TABLE}/index/${MY_SECONDARY_INDEX_NAME}"
      RoleARN: !GetAtt ScalingRole.Arn
      ScalableDimension: dynamodb:index:WriteCapacityUnits
      ServiceNamespace: dynamodb
  SecIndexReadCapacity:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      MaxCapacity: 1000
      MinCapacity: 15
      ResourceId: !Sub "table/${MY_MAIN_TABLE}/index/MY_SECONDARY_INDEX_NAME"
      RoleARN: !GetAtt ScalingRole.Arn
      ScalableDimension: dynamodb:index:ReadCapacityUnits
      ServiceNamespace: dynamodb
  SecIndexWriteScalingPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: SecIndexWriteScalingPolicy
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref SecIndexWriteCapacity
      TargetTrackingScalingPolicyConfiguration:
        TargetValue: 50.0
        ScaleInCooldown: 30
        ScaleOutCooldown: 1
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBWriteCapacityUtilization
  SecIndexReadScalingPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: SecIndexReadScalingPolicy
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref SecIndexReadCapacity
      TargetTrackingScalingPolicyConfiguration:
        TargetValue: 50.0
        ScaleInCooldown: 30
        ScaleOutCooldown: 0
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBReadCapacityUtilization
Related