问题
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