我希望有人可以帮助我使用 Dynamo CLI 语法。
我无法从 CLI 创建全局二级索引。
索引之前的脚本按预期工作:
aws dynamodb create-table \
--table-name a.b.c \
--attribute-definitions \
AttributeName=TransactionID,AttributeType=S \
--key-schema \
AttributeName=TransactionID,KeyType=HASH \
--provisioned-throughput\
ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url $DATABASE_ENDPOINT_URL
当我添加索引时,出现错误:
aws dynamodb create-table \
--table-name a.b.c \
--attribute-definitions \
AttributeName=TransactionID,AttributeType=S \
AttributeName=BatchID,AttributeType=S \
AttributeName=TransactionStatus,AttributeType=S \
--key-schema \
AttributeName=TransactionID,KeyType=HASH \
--global-secondary-indexes IndexName=a.b.indexName,\
KeySchema=["{AttributeName=BatchID,KeyType=HASH}","{AttributeName=TransactionStatus,KeyType=RANGE}"],\
Projection="{ProjectionType=KEYS_ONLY}",\
ProvisionedThroughput="{ReadCapacityUnits=5,WriteCapacityUnits=5}"\
--provisioned-throughput\
ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url $DATABASE_ENDPOINT_URL
我收到的错误是:
Error parsing parameter '--global-secondary-indexes': Expected: '<second>', received: '<none>' for input: IndexName=a.b.indexName,
这似乎是直接来自示例的。我还尝试使用基于其他问题的一些示例的文件,但也没有运气。
将所有内容放在一行上就可以解决问题。
这有效:
aws dynamodb create-table \
--table-name a.b.c \
--attribute-definitions \
AttributeName=TransactionID,AttributeType=S \
AttributeName=BatchID,AttributeType=S \
AttributeName=TransactionStatus,AttributeType=S \
--key-schema \
AttributeName=TransactionID,KeyType=HASH \
--global-secondary-indexes IndexName=a.b.indexName,KeySchema=["{AttributeName=BatchID,KeyType=HASH}","{AttributeName=TransactionStatus,KeyType=RANGE}"],Projection="{ProjectionType=KEYS_ONLY}",ProvisionedThroughput="{ReadCapacityUnits=5,WriteCapacityUnits=5}"\
--provisioned-throughput\
ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url $DATABASE_ENDPOINT_URL
我遇到了同样的问题,即正斜杠续行添加了额外的不需要的空格。然而我们发现我们可以利用 bash 引用行继续来分成单独的行。在哪里放置引号有多种选择,但这似乎格式很好,便于阅读:
aws dynamodb create-table \
--table-name a.b.c \
--attribute-definitions \
AttributeName=TransactionID,AttributeType=S \
AttributeName=BatchID,AttributeType=S \
AttributeName=TransactionStatus,AttributeType=S \
--key-schema \
AttributeName=TransactionID,KeyType=HASH \
--global-secondary-indexes \
IndexName=a.b.indexName,KeySchema=["
{AttributeName=BatchID,KeyType=HASH},
{AttributeName=TransactionStatus,KeyType=RANGE}
"],"Projection={
ProjectionType=KEYS_ONLY
"},ProvisionedThroughput={"
ReadCapacityUnits=5,WriteCapacityUnits=5
"} \
--provisioned-throughput \
ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url $DATABASE_ENDPOINT_URL