我們的團隊非常高興地看到針對AWS DynamoDB宣佈的自動縮放功能,並且在通過在Web界面中添加配置嘗試它時,我們發現這很適合我們的應用程序'需要。通過CloudFormation爲已有表添加自動縮放比例
但是,嘗試通過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"
}
}
}
}
}
}
如果任何人都可以提供一些線索,爲什麼發生這種情況,我會非常感激:)
奇怪的是,似乎只有一個特定的表存在問題 - 並且通過控制檯添加或刪除自動縮放無助於 - 腳本仍然因提到的錯誤而失敗。解決此問題的唯一方法是通過CF更新預配置容量(不可擴展),然後才能通過相同的CF腳本添加自動縮放。 –