AWS:无法在一次更新中执行多个 GSI 创建或删除

Z M*_*ars 8 amazon-web-services amazon-dynamodb serverless aws-serverless

所以我在无服务器部署过程中遇到了这个问题:

\n
ServerlessError: An error occurred: MyDdbTable - Cannot perform more than one GSI creation or deletion in a single update.\n
Run Code Online (Sandbox Code Playgroud)\n

我的DDB表配置是这样的: \n serverless.yml中的配置

\n
      AttributeDefinitions:\n          - AttributeName: externalId\n            AttributeType: S\n          - AttributeName: code\n            AttributeType: S\n          - AttributeName: accountId\n            AttributeType: S\n        KeySchema:\n          - AttributeName: externalId\n            KeyType: HASH\n          - AttributeName: code\n            KeyType: RANGE\n        GlobalSecondaryIndexes:\n          - IndexName: gsi-account-id\n            KeySchema:\n              - AttributeName: accountId\n                KeyType: HASH\n              - AttributeName: code\n                KeyType: RANGE\n            Projection:\n              ProjectionType: ALL\n          - IndexName: externalId\n            KeySchema:\n              - AttributeName: externalId\n                KeyType: HASH\n            Projection:\n              ProjectionType: ALL\n          - IndexName: code\n            KeySchema:\n              - AttributeName: code\n                KeyType: RANGE\n            Projection:\n              ProjectionType: ALL\n
Run Code Online (Sandbox Code Playgroud)\n

附加信息:

\n
    \n
  • 一 (1) 个索引已存在,它gsi-account-id具有两 (2) 个 keySchema,accountId并且code
  • \n
  • 我添加了两 (2) 个附加索引,它们是externalIdcode
  • \n
\n

目标:

\n

我的目标是添加这两 (2) 个附加索引(externalIdcode),但在进行无服务器部署时,我总是遇到上述问题。

\n

问题:

\n
    \n
  1. 我是否遇到此问题是因为代码已存在于第一个 keySchema (gsi-account-id) 中?
  2. \n
  3. 如果#1 不是答案,您对为什么我会遇到此问题有任何想法/建议吗?
  4. \n
\n

感谢那些在这方面帮助我的人。\xe2\x9d\xa4\xef\xb8\x8f

\n

Jas*_*rth 17

根据文档向现有表添加全局二级索引

每个 UpdateTable 操作只能创建一个全局二级索引。

您需要添加一个 GSI,部署该更改,然后添加第二个 GSI 并部署它。

  • 那就完蛋了。 (29认同)
  • AWS:“使用 IaC”。还有AWS:这个 (9认同)
  • 这不是 CDK 限制,而是 CloudFormation 限制。添加 GSI 并不是一项小任务。您实际上是在告诉 DynamoDB 扫描整个表并为 GSI 制作数据副本。请记住,DynamoDB 不知道索引中的字段是否实际上已经存在于数据中。因此,即使不包含在 GSI 中,也必须查看每条记录。 (3认同)