gpt4 book ai didi

amazon-web-services - 如何通过 AWS SAM 模板创建具有自动缩放吞吐量的 DynamoDB 表

转载 作者:行者123 更新时间:2023-12-03 07:29:20 25 4
gpt4 key购买 nike

我正在尝试创建 AWS SAM。我的 Lambda 对 DynamoDB 表执行一些写入操作,并且表预配置的吞吐量应自动缩放。如何在 template.yml 文件中提及?

这是我的表定义

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

最佳答案

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

关于amazon-web-services - 如何通过 AWS SAM 模板创建具有自动缩放吞吐量的 DynamoDB 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65379014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com