我想从项目中的 4 个 GSI 中删除单个 GSI。 但 Amplify CLI 工具包仅提供删除所有 GSI 的选项。当我运行
amplify update storage
时,CLI 工具包在流程中询问以下选项:
Do you want to keep existing global secondary indexes created on your table? (Y/n) · no
对此选项选择“否”会立即删除所有 GSI。 (并且在 amplify cli 版本 12.10.3 中没有选择和删除单个 GSI 的选项)
当我对上述选项选择“否”并尝试将更改推送到服务器时,出现以下错误:
🛑 The following resources failed to deploy:
Resource Name: DynamoDBTable (AWS::DynamoDB::Table)
Event Type: update
Reason: Resource handler returned message: "Cannot perform more than one GSI creation or deletion in a single update" (RequestToken: fcd558ca-1d24-4590-d3b1-d5f57c0cc17f, HandlerErrorCode: InvalidRequest)
我试图找到一种方法来仅删除选定的GSI,但我没有找到任何这样的选项。
我设法通过进入
amplify/backend/storage/<dynamodbresourcename>/cli-inputs.json
文件删除单个 GSI,该文件的结构类似于以下内容:
{
"resourceName": "dbname",
"tableName": "dbnane",
"partitionKey": {
"fieldName": "pk",
"fieldType": "string"
},
"sortKey": {
"fieldName": "sk",
"fieldType": "string"
},
"gsi": [
{
"name": "gs1",
"partitionKey": {
"fieldName": "gs1pk",
"fieldType": "string"
},
"sortKey": {
"fieldName": "gs1sk",
"fieldType": "string"
}
},
{
"name": "gs2",
"partitionKey": {
"fieldName": "gs2pk",
"fieldType": "string"
},
"sortKey": {
"fieldName": "gs2sk",
"fieldType": "string"
}
},
{
"name": "gs3",
"partitionKey": {
"fieldName": "gs3pk",
"fieldType": "string"
},
"sortKey": {
"fieldName": "gs3sk",
"fieldType": "string"
}
}
],
"triggerFunctions": []
}
然后我简单地从
gsi
数组中删除了我想要删除的 GSI 的条目。例如,如果我想删除 gs3
,我从 gsi 数组中删除了该条目,之后 json 如下所示:
{
"resourceName": "dbname",
"tableName": "dbname",
"partitionKey": {
"fieldName": "pk",
"fieldType": "string"
},
"sortKey": {
"fieldName": "sk",
"fieldType": "string"
},
"gsi": [
{
"name": "gs1",
"partitionKey": {
"fieldName": "gs1pk",
"fieldType": "string"
},
"sortKey": {
"fieldName": "gs1sk",
"fieldType": "string"
}
},
{
"name": "gs2",
"partitionKey": {
"fieldName": "gs2pk",
"fieldType": "string"
},
"sortKey": {
"fieldName": "gs2sk",
"fieldType": "string"
}
}
],
"triggerFunctions": []
}
然后运行命令
amplify push storage
。
我希望这对某人有帮助。