You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地AWS CLI操作DynamoDB无法创建GSI求助

本地DynamoDB更新表添加GSI报InternalFailure错误的排查方案

问题场景

  • 本地DynamoDB版本:2.5.1
  • 启动命令:java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -port 8001
  • 已成功创建表GameScores2,执行命令:
--endpoint-url http://localhost:8001    
--table-name GameScores2     
--attribute-definitions AttributeName=GameTitle,AttributeType=S  AttributeName=UserId,AttributeType=S    
--key-schema AttributeName=UserId,KeyType=HASH AttributeName=GameTitle,KeyType=RANGE     
--provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5```
- 执行`UpdateTable`添加全局二级索引(GSI)时,触发错误:
`An error occurred (InternalFailure) when calling the UpdateTable operation (reached max retries: 9): The request processing has failed because of an unknown error, exception or failure`
- 直接创建包含GSI的表可正常执行,但需更新现有表。

## 可能原因及解决办法
- **共享数据库模式限制**
  使用`-sharedDb`参数启动时,本地DynamoDB将所有数据存储在单个SQLite文件中,这种模式下更新表结构(含添加GSI)易触发底层锁冲突或事务异常,尤其表中已有数据时。
  解决:去掉`-sharedDb`参数,以独立数据库模式启动服务,重新创建表后再执行`UpdateTable`操作。

- **已有数据导致索引构建异常**
  本地DynamoDB 2.5.1版本在为带数据的表添加GSI时,全表扫描构建索引的过程可能存在bug。
  解决:
  1. 导出表中数据,删除原表,创建带GSI的新表后重新导入数据;
  2. 升级至更新版本的本地DynamoDB(如最新2.x稳定版或3.x预览版),新版本通常修复了这类内部错误。

- **读写容量设置冲突**
  添加GSI时指定的读写容量若与原表设置不兼容,可能触发内部错误。检查`UpdateTable`命令中GSI的`ProvisionedThroughput`参数,确保数值合理(不超过原表容量限制,或未遗漏参数)。

- **命令语法隐性问题**
  即便排查过语法,仍可能存在参数顺序、空格或引号的隐性问题。确保`--global-secondary-indexes`参数格式正确,示例如下:
  ```aws dynamodb update-table
  --endpoint-url http://localhost:8001
  --table-name GameScores2
  --attribute-definitions AttributeName=NewGSIKey,AttributeType=S
  --global-secondary-indexes "IndexName=MyGSI,KeySchema=[{AttributeName=NewGSIKey,KeyType=HASH}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=5,WriteCapacityUnits=5}"

注意引号使用,Windows环境下可能需要调整引号格式。

内容的提问来源于stack exchange,提问作者Tesouro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 04:12:41