如何使用Cloudformation模板对dynamodb二级索引进行自动调整?

时间:2017-07-27 17:40:12

标签: amazon-web-services amazon-dynamodb

我已经看到了向带有cloudformation的表添加自动缩放的示例,但除了"将相同的设置应用于全局二级索引"在dynamodb控制台中的复选框,我没有看到使用云形态模板定义它的方法。

2 个答案:

答案 0 :(得分:2)

可以将辅助索引定义为自动缩放目标。

您只需使用resourceId作为后缀,并使用/index/**YOUR_INDEX_NAME**dynamodb:index:WriteCapacityUnits作为dynamodb:index:ReadCapacityUnits,将索引指定为ScalableDimension

E.g。

  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

另见https://aws.amazon.com/blogs/database/how-to-use-aws-cloudformation-to-configure-auto-scaling-for-amazon-dynamodb-tables-and-indexes/

答案 1 :(得分:0)

实际上这是可能的。

遵循DynamoDB/CloudFormation的官方AWS示例,但是对于每个GSI,您需要创建单独的ScalableTarget和可扩展的策略。在ScalableTarget属性中,对ResourceId使用table/my-table/index/my-table-index表示法。