amazon-web-services - 为什么通过 cdk 向 dynamodb 表添加二级索引需要重新创建该表?

标签 amazon-web-services amazon-dynamodb aws-cloudformation aws-cdk

向(之前通过 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"
  }
  1. 这是为什么?
  2. 是否可以通过某种方式阻止这种情况,或者除了通过 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/

相关文章:

java - aws-java-sdk-cognitoidp 与 aws-java-sdk-cognitoidentity 之间的区别?

java - 如何将输入传输到由 DynamoDB 中的更改触发的 lambda

concurrency - DynamoDB 自动更新计数器

amazon-web-services - aws pipeline 角色无权对跨账户角色执行 AssumeRole

aws-cloudformation - AWS Cloudformation 陷入 UPDATE_ROLLBACK_FAILED 状态

amazon-web-services - AWS CDK IAM 联合和用户 IamRoleAccess?

amazon-web-services - AWS 时间流 : Unable to ingest records into AWS Timestream

ios - CognitoIdentityCredentials 无权执行 : dynamodb:Query on resource:

elasticsearch - 如何使用Logstash将数据从AWS dynamo DB加载到Elasticsearch

amazon-web-services - 在 Cloudformation-YAML 中的单个资源中添加不同的参数值