DynamoDB的自动缩放不是DynamoD B 的属性。相反,它是Application Auto Scaling的属性,您应该使用它的资源来定义表的缩放。
下面是使用固定表定义(您的 DynamoDB 表不正确)进行读取容量自动扩展的示例。对于自动扩展写入容量,您必须添加类似的资源。
Resources:
myDB:
Type: AWS::DynamoDB::Table
Properties:
TableName: my-awesome-database
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
AttributeDefinitions:
- AttributeName: e_id
AttributeType: S
- AttributeName: es
AttributeType: S
- AttributeName: ts
AttributeType: S
KeySchema:
- AttributeName: e_id
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: my-awesome-database-index
KeySchema:
- AttributeName: es
KeyType: HASH
- AttributeName: ts
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
MyScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 10
MinCapacity: 1
ResourceId: !Sub "table/${myDB}"
RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
ScalableDimension: dynamodb:table:ReadCapacityUnits
ServiceNamespace: dynamodb
MyScalableTargetGSI:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 10
MinCapacity: 1
ResourceId: !Sub "table/${myDB}/index/my-awesome-database-index"
RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
ScalableDimension: dynamodb:index:ReadCapacityUnits
ServiceNamespace: dynamodb
MyTargetTracking:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: my-scaling-policy
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref MyScalableTarget
TargetTrackingScalingPolicyConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBReadCapacityUtilization
TargetValue: 70
MyTargetTrackingGSI:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: my-scaling-policy
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref MyScalableTargetGSI
TargetTrackingScalingPolicyConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBReadCapacityUtilization
TargetValue: 70