向(之前通过 cdk 部署的)dynamodb 表添加二级索引,例如
table.addLocalSecondaryIndex({
indexName: "indexName",
sortKey: {
name: "keyName",
type: dynamodb.AttributeType.STRING,
},
projectionType: dynamodb.ProjectionType.INCLUDE,
nonKeyAttributes: ["attr1", "attr2"],
});
需要重新创建表,如 cdk 创建的 cloudformation 更改集中所示:
"resourceChange": {
"logicalResourceId": "---ID---",
"action": "Modify",
"physicalResourceId": "---ID---",
"resourceType": "AWS::DynamoDB::Table",
"replacement": "True",
"moduleInfo": null,
"details": [
{
"target": {
"name": "LocalSecondaryIndexes",
"requiresRecreation": "Always",
"attribute": "Properties"
},
"causingEntity": null,
"evaluation": "Static",
"changeSource": "DirectModification"
}
],
"changeSetId": null,
"scope": [
"Properties"
]
},
"type": "Resource"
}
- 这是为什么?
- 是否可以通过某种方式阻止这种情况,或者除了通过 aws-console 手动添加索引之外还有其他解决方法吗?
干杯, 赫尔格
最佳答案
Why is that?
更改为LocalSecondaryIndexes需要替换 DynamoDB 表,因为 LSI 只能在表创建时创建。相反,对 GlobalSecondaryIndexes 的修改导致无中断。
Can that be prevented somehow or is there a Workaround besides adding the index manually via the aws-console?
遗憾的是,如上所述,没有办法阻止这种情况发生。如果您不想继续更换表格,可以使用 GSI。
关于amazon-web-services - 为什么通过 cdk 向 dynamodb 表添加二级索引需要重新创建该表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65064754/