Reputation: 316
I am trying to create a AWS SAM. My Lambda does some write operation on DynamoDB table and the table provisioned throughput should be Autoscaled. How can I mention in the template.yml
file?
here is my table definition
Resources:
myDB:
Type: AWS::DynamoDB::Table
Properties:
TableName: my-awesome-database
AttributeDefinitions:
- AttributeName: e_id
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
Upvotes: 0
Views: 955
Reputation: 238081
Autoscaling of DynamoDB is not a property of DynamoDB. Instead, it is a property of Application Auto Scaling and you should use its resources to define scaling for your table.
An example for read-capacity auto-scaling with fixed table definition (your DynamoDB table is incorrect) is below. For auto-scaling write capacity you have to add similar resources.
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
Upvotes: 4