问题描述
所以我在无服务器部署期间遇到了这个问题:
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,accountId
和code
- 我添加了两 (2) 个附加索引,分别是
externalId
和code
目标:
我的目标是添加这两 (2) 个附加索引(externalId
和 code
),但在进行无服务器部署时,我总是遇到上述问题。
问题:
感谢那些在这方面帮助我的人。 ❤️
解决方法
根据文档 Adding a Global Secondary Index to an Existing Table
每个 UpdateTable 操作只能创建一个全局二级索引。
您需要添加一个 GSI,部署该更改,然后添加第二个并部署它。