Amazon dynamodb 使用CloudFormation为现有dynamoDB表创建二级全局索引
DynamoDB表已经创建并在生产中运行。根据当前用例,计划添加新的二级全局索引。这可以通过AWS SDK实现,是否可以使用CloudFormation脚本更新DynamoDB表Amazon dynamodb 使用CloudFormation为现有dynamoDB表创建二级全局索引,amazon-dynamodb,amazon-cloudformation,secondary-indexes,Amazon Dynamodb,Amazon Cloudformation,Secondary Indexes,DynamoDB表已经创建并在生产中运行。根据当前用例,计划添加新的二级全局索引。这可以通过AWS SDK实现,是否可以使用CloudFormation脚本更新DynamoDB表 任何帮助都将不胜感激。创建新的CloudFormation脚本或使用 Resources DDBTable: Type: AWS::DynamoDB::Table Properties: TableName: YOUR_EXISTING_TABLE_NAME Attribute
任何帮助都将不胜感激。创建新的CloudFormation脚本或使用
Resources
DDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: YOUR_EXISTING_TABLE_NAME
AttributeDefinitions: #List out all existing cols here
-
AttributeName: "ColX" # hash key
AttributeType: "S"
-
AttributeName: "ColY" # range key
AttributeType: "S"
-
AttributeName: "ColZ" # used for your Global Secondary Index
AttributeType: "S"
KeySchema: # List out your main Hash & Range Key
-
AttributeName: "ColX"
KeyType: "HASH"
-
AttributeName: "ColY"
KeyType: "RANGE"
GlobalSecondaryIndexes: # new Global Secondary Index
- IndexName: INDEX_NAME
KeySchema:
- AttributeName: ColZ #different than your main table Hash Key
KeyType: HASH
Projection:
ProjectionType: ALL
此脚本将尝试使用现有的\u table\u名称创建表,但由于表已存在而失败。希望首先使用CloudFormation创建表。否则,就无法获取现有资源并将其包含在新的CloudFormation堆栈中。如果表是首先使用CF创建的,那么您可以修改资源并再次部署它。但CF并不用于修改与堆栈无关的现有资源。我可以使用CF而不是辅助索引为相同的现有dynamo表创建自动缩放策略。这是针对dynamoDB GSI的,而不是上述问题的重复。