Amazon dynamodb AWS SAM在添加SortKey或GlobalSecondaryIndex时重新创建DynamoDB表
我正在使用部署DynamoDB表,我的template.yaml如下所示:Amazon dynamodb AWS SAM在添加SortKey或GlobalSecondaryIndex时重新创建DynamoDB表,amazon-dynamodb,aws-sam,Amazon Dynamodb,Aws Sam,我正在使用部署DynamoDB表,我的template.yaml如下所示: AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 DynamoDBTable: Type: AWS::DynamoDB::Table Properties: BillingMode: PAY_PER_REQUEST AttributeDefinition
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: owner
AttributeType: S
KeySchema:
- AttributeName: owner
KeyType: HASH
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: owner
AttributeType: S
- AttributeName: Timestamp
AttributeType: S
KeySchema:
- AttributeName: owner
KeyType: HASH
- AttributeName: Timestamp
KeyType: RANGE
GlobalSecondaryIndexes:
- IndexName: TestIndex
KeySchema:
- AttributeName: owner
KeyType: HASH
- AttributeName: Timestamp
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
我确实sam构建和&sam部署来(重新)部署它。
添加sortKey和/或GlobalSecondaryIndex时,yaml文件如下所示:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: owner
AttributeType: S
KeySchema:
- AttributeName: owner
KeyType: HASH
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: owner
AttributeType: S
- AttributeName: Timestamp
AttributeType: S
KeySchema:
- AttributeName: owner
KeyType: HASH
- AttributeName: Timestamp
KeyType: RANGE
GlobalSecondaryIndexes:
- IndexName: TestIndex
KeySchema:
- AttributeName: owner
KeyType: HASH
- AttributeName: Timestamp
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
根据更新说明,这些字段应该是可能的(无中断)。
但在我的例子中,deploy命令总是重新创建整个表(删除所有数据)。
我做错什么了吗
编辑
也许我的解释不清楚。我尝试同时添加(GSI和sortKey),但我也尝试逐个添加,即仅添加GSI。添加排序键或更改键模式需要替换表。有关表定义,请参见正确的
添加/更改LSI也需要更换。
可以不间断地添加GSI
虽然我认为更改GSI键模式也需要更换GSI…但文档似乎暗示它没有。DynamoDb表键模式和LSI只能在表创建期间设置,并且以后只能添加GSI
为了增加它,我们必须在Sam/CloudFormation中将name属性添加到数据库、Dynamo表等资源中,以避免被删除。当资源需要替换时,部署将失败,而不是删除并用新资源替换它。
例:
如上所述。如果我只添加GSI(不接触KeySchema),它将尝试重新创建表。TableName
是键。谢谢