aws-cli dynamodb create table with multiple secondary index

做~自己de王妃 提交于 2021-01-28 09:40:31

问题


I am trying to create a dynamodb table with 2 local secondary indexes. I did the following and only the latter index(index-2) applied. What's the correct way of doing this?

aws dynamodb create-table \
 --table-name test_table_name \
 --attribute-definitions \
     AttributeName=type,AttributeType=S \
     ...
 --key-schema \
     AttributeName=type,KeyType=HASH \
     AttributeName=id,KeyType=RANGE \
 --provisioned-throughput \
     ReadCapacityUnits=5,WriteCapacityUnits=5 \
 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
 --local-secondary-indexes \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \
 --region us-east-1

回答1:


You only need to specify single --local-secondary-indexes such as

before

 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
 --local-secondary-indexes \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \

After

 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \

Final

aws dynamodb create-table \
 --table-name test_table_name \
 --attribute-definitions \
     AttributeName=type,AttributeType=S \
     ...
 --key-schema \
     AttributeName=type,KeyType=HASH \
     AttributeName=id,KeyType=RANGE \
 --provisioned-throughput \
     ReadCapacityUnits=5,WriteCapacityUnits=5 \
 --local-secondary-indexes \
     'IndexName=index-1,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk1,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[A,B,C,D]}' \
     'IndexName=index-2,KeySchema=[{AttributeName=type,KeyType=HASH},{AttributeName=sk2,KeyType=RANGE}],Projection={ProjectionType=INCLUDE,NonKeyAttributes=[B,D,F,H]}' \
 --region us-east-1


来源:https://stackoverflow.com/questions/52402300/aws-cli-dynamodb-create-table-with-multiple-secondary-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!