微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决AWS:不能在一次更新中执行多个 GSI 创建或删除

所以我在无服务器部署期间遇到了这个问题:

ServerlessError: An error occurred: MyDdbTable - Cannot perform more than one GSI creation or deletion in a single update.

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

      AttributeDeFinitions:
          - AttributeName: externalId
            AttributeType: S
          - AttributeName: code
            AttributeType: S
          - AttributeName: accountId
            AttributeType: S
        KeySchema:
          - AttributeName: externalId
            KeyType: HASH
          - AttributeName: code
            KeyType: RANGE
        GlobalSecondaryIndexes:
          - IndexName: gsi-account-id
            KeySchema:
              - AttributeName: accountId
                KeyType: HASH
              - AttributeName: code
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
          - IndexName: externalId
            KeySchema:
              - AttributeName: externalId
                KeyType: HASH
            Projection:
              ProjectionType: ALL
          - IndexName: code
            KeySchema:
              - AttributeName: code
                KeyType: RANGE
            Projection:
              ProjectionType: ALL

其他信息:

  • 一 (1) 个索引已经存在,即 gsi-account-id,其中有两 (2) 个 keySchema,accountIdcode
  • 添加了两 (2) 个附加索引,分别是 externalIdcode

目标:

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

问题:

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

感谢那些在这方面帮助我的人。 ❤️

解决方法

根据文档 Adding a Global Secondary Index to an Existing Table

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。