对于已存在的表,通过CloudFormation为AWS DynamoDB添加自动扩展

时间:2017-09-01 19:33:18

标签: amazon-web-services amazon-dynamodb amazon-cloudformation autoscaling

我们的团队非常高兴看到为AWS DynamoDB宣布了自动缩放功能,并且在通过在网络界面中添加配置进行尝试时,我们发现我们的应用程序与我们的应用程序相匹配。需要。

但是,尝试通过CF添加相同的配置已经证明有点复杂。按照本文中提供的示例 - http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-examples-application-autoscaling - 下面是结果,但不起作用。堆栈细节:

17:02:25 UTC+0300 UPDATE_ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack my-stack The following resource(s) failed to create: [WriteCapacityScalableTarget]. 17:02:24 UTC+0300 CREATE_FAILED AWS::ApplicationAutoScaling::ScalableTarget WriteCapacityScalableTarget table/TableName|dynamodb:table:WriteCapacityUnits|dynamodb already exists 17:02:18 UTC+0300 CREATE_IN_PROGRESS AWS::ApplicationAutoScaling::ScalableTarget WriteCapacityScalableTarget
17:02:15 UTC+0300 CREATE_COMPLETE AWS::IAM::Role ScalingRole
17:01:42 UTC+0300 CREATE_IN_PROGRESS AWS::IAM::Role ScalingRole Resource creation Initiated 17:01:42 UTC+0300 CREATE_IN_PROGRESS AWS::IAM::Role ScalingRole
17:01:37 UTC+0300 UPDATE_IN_PROGRESS AWS::CloudFormation::Stack my-stack User Initiated

我的CF脚本如下:

{
  "Resources": {
    "MyCustomTableName": {
      "Type": "AWS::DynamoDB::Table",
      "Properties": {
        "TableName": "TableName",
        "AttributeDefinitions": [
          {
            "AttributeName": "someAttribute1:someAttribute2",
            "AttributeType": "S"
          }
        ],
        "KeySchema": [
          {
            "AttributeName": "someAttribute1:someAttribute2",
            "KeyType": "HASH"
          }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": 1,
          "WriteCapacityUnits": 1
        },
        "StreamSpecification": {
          "StreamViewType": "NEW_AND_OLD_IMAGES"
        }
      }
    },
    "WriteCapacityScalableTarget": {
      "Type": "AWS::ApplicationAutoScaling::ScalableTarget",
      "Properties": {
        "MaxCapacity": 30,
        "MinCapacity": 1,
        "ResourceId": {
          "Fn::Join": [
            "/",
            [
              "table",
              {
                "Ref": "MyCustomTableName"
              }
            ]
          ]
        },
        "RoleARN": {
          "Fn::GetAtt": [
            "ScalingRole",
            "Arn"
          ]
        },
        "ScalableDimension": "dynamodb:table:WriteCapacityUnits",
        "ServiceNamespace": "dynamodb"
      }
    },
    "ScalingRole": {
      "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": "*"
                }
              ]
            }
          }
        ]
      }
    },
    "WriteScalingPolicy": {
      "Type": "AWS::ApplicationAutoScaling::ScalingPolicy",
      "Properties": {
        "PolicyName": "WriteAutoScalingPolicy",
        "PolicyType": "TargetTrackingScaling",
        "ScalingTargetId": {
          "Ref": "WriteCapacityScalableTarget"
        },
        "TargetTrackingScalingPolicyConfiguration": {
          "TargetValue": 70.0,
          "ScaleInCooldown": 60,
          "ScaleOutCooldown": 60,
          "PredefinedMetricSpecification": {
            "PredefinedMetricType": "DynamoDBWriteCapacityUtilization"
          }
        }
      }
    }
  }
}

如果有人能说清楚为什么会发生这种情况,我会非常感激:)

2 个答案:

答案 0 :(得分:4)

转到错误消息

CREATE_FAILED AWS::ApplicationAutoScaling::ScalableTarget WriteCapacityScalableTarget table/TableName|dynamodb:table:WriteCapacityUnits|dynamodb already exists

您正在创建名为"TableName": "TableName"的DynamoDB资源。您不能在区域中拥有两个具有相同名称的dynamoDB表。

转到DynamoDB控制台并检查是否有任何此类表并将其删除。发布模板应该可以正常工作。

选项2:如果要继续使用现有表,则可以从CF模板中删除AWS :: DynamoDB :: Table资源。

答案 1 :(得分:0)

对我来说,为现有的发电机表设置自动缩放时出现此错误。确保已删除为该发电机表设置的任何手动(通过控制台)自动缩放。然后重新执行,堆栈将达到UPDATE_COMPLETE阶段。