DynamoDb使用cloudformation对多个表重新使用可伸缩目标

时间:2019-07-08 07:22:46

标签: amazon-dynamodb amazon-cloudformation autoscaling

我正在尝试向多个DDB表添加自动缩放,因为所有表的流量模式都相同,因此它们的自动缩放配置将完全相同。 我知道可以通过为每个表创建可伸缩目标来实现此目的的方法,但是由于我希望所有表都使用相同的配置,因此我想知道是否可以重复使用可伸缩目标

  WriteCapacityScalableTarget:
    Type: "AWS::ApplicationAutoScaling::ScalableTarget"
    Properties:
      MaxCapacity: 30
      MinCapacity: 5
      ResourceId:
        Fn::Join:
          - /
          - - table
            - Ref: FooTable
      RoleARN:
        Fn::GetAtt: DynamoDBAutoScalingRole.Arn
      ScalableDimension: "dynamodb:table:WriteCapacityUnits"
      ServiceNamespace: dynamodb

  WriteScalingPolicy:
    Type: "AWS::ApplicationAutoScaling::ScalingPolicy"
    Properties:
      PolicyName: WriteAutoScalingPolicy
      PolicyType: TargetTrackingScaling
      ScalingTargetId:
        Ref: WriteCapacityScalableTarget
      TargetTrackingScalingPolicyConfiguration:
        TargetValue: 80 
        ScaleInCooldown: 10 
        ScaleOutCooldown: 10 
        PredefinedMetricSpecification:
          PredefinedMetricType: DynamoDBWriteCapacityUtilization

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

这对在单个表上启用自动缩放效果很好,但是当我在多个表上尝试自动缩放失败时,我会像-

  WriteCapacityScalableTarget:
    Type: "AWS::ApplicationAutoScaling::ScalableTarget"
    Properties:
      MaxCapacity: 30
      MinCapacity: 5
      ResourceId:
        Fn::Join:
          - /
          - - table
            - Ref: FooTable
            - table 
            - Ref: BarTable
      RoleARN:
        Fn::GetAtt: DynamoDBAutoScalingRole.Arn
      ScalableDimension: "dynamodb:table:WriteCapacityUnits"
      ServiceNamespace: dynamodb

以上目标无法创建,我们可以以相同的方式将可扩展目标用于索引,但是也可以用于多个表吗? 如果是,该如何实现?

0 个答案:

没有答案