创建DynamoDB CloudFormation模板时,需要指定ProvisionedThroughput:
但是我也看到这个文档说当你通过控制台创建一个表时,默认情况下会设置Auto Scaling。
我的问题是:我是否需要使用Cloudformation来使DynamoDB表自动缩放?
答案 0 :(得分:6)
使用CloudFormation配置Auto Scaling DynamoDB尚不可用。
CloudFormation不会立即支持AWS服务的新功能。添加支持的时间延迟可能会有所不同,但通常需要几个月。
修改强>
亚马逊刚刚宣布Target Tracking Policies,这是使用单独的资源类型AWS::ApplicationAutoScaling::ScalingPolicy在CloudFormation中实现的。
您仍然必须使用特定的读写吞吐量配置DynamoDB表,但是分别为读取和其他写入策略配置扩展策略。
亚马逊在其文档中提供了以下示例。
{
"Resources": {
"DDBTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"AttributeDefinitions": [
{
"AttributeName": "ArtistId",
"AttributeType": "S"
},
{
"AttributeName": "Concert",
"AttributeType": "S"
},
{
"AttributeName": "TicketSales",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "ArtistId",
"KeyType": "HASH"
},
{
"AttributeName": "Concert",
"KeyType": "RANGE"
}
],
"GlobalSecondaryIndexes": [
{
"IndexName": "GSI",
"KeySchema": [
{
"AttributeName": "TicketSales",
"KeyType": "HASH"
}
],
"Projection": {
"ProjectionType": "KEYS_ONLY"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
}
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
}
}
},
"WriteCapacityScalableTarget": {
"Type": "AWS::ApplicationAutoScaling::ScalableTarget",
"Properties": {
"MaxCapacity": 15,
"MinCapacity": 5,
"ResourceId": { "Fn::Join": [
"/",
[
"table",
{ "Ref": "DDBTable" }
]
] },
"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": 50.0,
"ScaleInCooldown": 60,
"ScaleOutCooldown": 60,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "DynamoDBWriteCapacityUtilization"
}
}
}
}
}
}
答案 1 :(得分:2)
The autoscaling can be done using CloudFormation.
Refer this answer.
答案 2 :(得分:1)
这似乎有效:
"ReadScaling" : {
"Type" : "AWS::ApplicationAutoScaling::ScalableTarget",
"Properties" : {
"MaxCapacity" : "<MAX CAPACITY>,
"MinCapacity" : "<MIN CAPACITY>,
"ResourceId" : "table/<TABLE NAME>",
"RoleARN" : "<IAM ROLE ARN>",
"ScalableDimension" : "dynamodb:table:ReadCapacityUnits",
"ServiceNamespace" : "dynamodb"
}
},
"ReadScalingPolicy" : {
"Type" : "AWS::ApplicationAutoScaling::ScalingPolicy",
"Properties" : {
"PolicyName" : "ReadScalingPolicy",
"PolicyType" : "TargetTrackingScaling",
"ResourceId" : "table/<TABLE NAME>",
"ScalableDimension" : "dynamodb:table:ReadCapacityUnits",
"ServiceNamespace" : "dynamodb",
"TargetTrackingScalingPolicyConfiguration" : {
"PredefinedMetricSpecification": {
"PredefinedMetricType": "DynamoDBReadCapacityUtilization"
},
"ScaleInCooldown" : "60",
"ScaleOutCooldown" : "60",
"TargetValue" : "70"
}
},
"DependsOn" : "ReadScaling"
},
有关IAM角色的规范
,请参阅 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AutoScaling.CLI.html