【问题标题】:How can dynamodb secondary indexes be autoscaled with Cloudformation templates?如何使用 Cloudformation 模板自动缩放 dynamodb 二级索引?
【发布时间】:2018-06-01 17:58:50
【问题描述】:

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

【问题讨论】:

    标签: amazon-web-services amazon-dynamodb


    【解决方案1】:

    可以将二级索引定义为自动缩放目标。

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

    例如

      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/

    【讨论】:

    • 对于resourceId,这应该是表和索引的实际DynamoDB名称吗?还是 CloudFormation 参考?
    • 发现它是resourceId中表和索引的实际DynamoDB名称
    【解决方案2】:

    其实是可以的。

    遵循DynamoDB/CloudFormation 的官方 AWS 示例,但您需要为每个 GSI 创建单独的 ScalableTarget 和 Scalable Policy。在 ScalableTarget 属性中,ResourceId 使用 table/my-table/index/my-table-index 表示法。

    【讨论】:

      猜你喜欢
      • 2021-03-22
      • 2020-02-27
      • 2017-12-27
      • 2020-10-26
      • 2014-02-17
      • 1970-01-01
      • 2015-11-05
      • 2018-11-08
      • 1970-01-01
      相关资源
      最近更新 更多