BSh*_*oks 3 command-line command-line-interface amazon-dynamodb
创建全局二级索引时,用于Dynamodb创建表的AWS CLI有点混乱。在CLI文档中,它表示全局二级索引可以用以下表达式(简写)表示:
IndexName=string,KeySchema=[{AttributeName=string,KeyType=string},{AttributeName=string,KeyType=string}],Projection={ProjectionType=string,NonKeyAttributes=[string,string]},ProvisionedThroughput={ReadCapacityUnits=long,WriteCapacityUnits=long} ...
Run Code Online (Sandbox Code Playgroud)
我的解释是,我应该做
--global-secondary-indexes IndexName=requesterIndex,Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=1,WriteCapacityUnits=1}
Run Code Online (Sandbox Code Playgroud)
请注意,我这里不包括KeySchema来推断复杂性。控制台给我以下错误:
Parameter validation failed:
Missing required parameter in GlobalSecondaryIndexes[0]: "KeySchema"
Unknown parameter in GlobalSecondaryIndexes[0]: "WriteCapacityUnits", must be one of: IndexName, KeySchema, Projection, ProvisionedThroughput
Invalid type for parameter GlobalSecondaryIndexes[0].ProvisionedThroughput, value: ReadCapacityUnits=1, type: <class 'str'>, valid types: <class 'dict'>
Run Code Online (Sandbox Code Playgroud)
因此,AWS CLI以某种方式无法识别ProvisionedThroughput的映射表达式。我尝试了几种方法来表达它,但无法使其起作用。我也未能在Google中找到任何描述其操作方法的网页。
小智 6
这是我用来从命令行在aws文档中创建Reply示例的cli调用。我可以在环境中设置最后使用的$ EP来在EP="--endpoint-url http://localhost:8000"本地dynamodb而不是aws上创建表。
aws dynamodb create-table --table-name Reply --attribute-definitions \
AttributeName=Id,AttributeType=S AttributeName=ReplyDateTime,AttributeType=S \
AttributeName=PostedBy,AttributeType=S AttributeName=Message,AttributeType=S \
--key-schema AttributeName=Id,KeyType=HASH \
AttributeName=ReplyDateTime,KeyType=RANGE --global-secondary-indexes \
IndexName=PostedBy-Message-Index,KeySchema=["\
{AttributeName=PostedBy,KeyType=HASH}","\
{AttributeName=Message,KeyType=RANGE}"],Projection="{ProjectionType=INCLUDE \
,NonKeyAttributes=["ReplyDateTime"]}",ProvisionedThroughput="\
{ReadCapacityUnits=10,WriteCapacityUnits=10}" --provisioned-throughput \
ReadCapacityUnits=5,WriteCapacityUnits=4 $EP
Run Code Online (Sandbox Code Playgroud)
阅读Github上的AWS CLI源代码,它可以解析双引号内容。因此在脚本中添加双引号解决了问题。有新的代码 -
--global-secondary-indexes IndexName=requesterIndex,Projection={ProjectionType=ALL},ProvisionedThroughput="{ReadCapacityUnits=${CURRENT_READUNIT},WriteCapacityUnits=${CURRENT_WRITEUNIT}}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3383 次 |
| 最近记录: |