您如何管理基于自动缩放的 dynamodb table 的全局二级索引的写入容量?

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

全局二级索引的容量配置与应用它们的 tables 分开。如果为 GSI 分配的写入容量不足,则 writes to the table are throttled。因此,如果触发写入 table 的自动缩放,那么应该期望 GSI 的写入容量需要作为响应进行管理。

tablereads/writes 的自动缩放可以通过 AWS 管理控制台、CLI 或使用 CloudFormation 配置。该文档发布了示例 JSON/YAML 以完成 table 配置。但是,当我尝试在自动缩放的 table 上创建新的 GSI 时,我看不到镜像 table 设置的选项。我也无法在文档中找到有关如何显式处理索引和自动缩放的 CLI 或 CloudFormation 示例。

那么您如何管理 GSI 的写入容量?我对事情应该如何运作的理解正确吗?或者 AWS "do the right thing"(无论如何,在他们看来)并与底层 table 并行自动缩放 GSI?

您可以为全局二级索引应用相同的自动缩放设置。根据AWS docs:

If you enable DynamoDB auto scaling for a table that has one or more global secondary indexes, we highly recommend that you also apply auto scaling uniformly to those indexes. You can do this by choosing Apply same settings to global secondary indexes in the AWS Management Console.

将二级索引定义为自动缩放目标是now possible。与正常 table 相比几乎相同。您只需更改 AWS::ApplicationAutoScaling::ScalableTarget.

resourceIdScalableDimension
  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