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

使用CLI创建带全局索引的DynamoDB表时参数验证失败如何解决?

修复DynamoDB全局索引创建的CLI参数错误

错误原因

你的命令报错是因为--global-secondary-indexes参数未正确包裹,导致CLI将逗号分隔的内容识别为多个独立参数,同时JSON格式的大括号写法在无引号时无法被解析为字典类型,最终触发参数类型验证失败。

修复方案

方案1:给全局索引参数整体加双引号

将--global-secondary-indexes后的所有内容用双引号包裹,确保CLI将其作为单个参数解析:

aws dynamodb create-table \
--table-name test1 \
--attribute-definitions AttributeName=id,AttributeType=S AttributeName=consumerId,AttributeType=S \
--key-schema AttributeName=id,KeyType=HASH \
--global-secondary-indexes "IndexName=consumerIdInd,KeySchema=[{AttributeName=consumerId,KeyType=HASH}],Projection={ProjectionType=ALL}"

方案2:使用AWS CLI原生嵌套参数写法

放弃JSON格式的括号,改用CLI支持的空格分隔嵌套结构写法,更易读且不易出错:

aws dynamodb create-table \
--table-name test1 \
--attribute-definitions AttributeName=id,AttributeType=S AttributeName=consumerId,AttributeType=S \
--key-schema AttributeName=id,KeyType=HASH \
--global-secondary-indexes \
    IndexName=consumerIdInd \
    KeySchema AttributeName=consumerId,KeyType=HASH \
    Projection ProjectionType=ALL

验证说明

两种方案都能正确将KeySchema解析为字典类型,满足DynamoDB的参数要求。执行修复后的命令后,你可以通过aws dynamodb describe-table --table-name test1确认表和全局索引是否创建成功。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 23:25:58