1

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 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.