Reputation: 929
I am trying to create a table from the CLI that has a few GSIs. However, It is returning an error:
Parameter validation failed: Missing required parameter in GlobalSecondaryIndexes[5]: "IndexName" Missing required parameter in GlobalSecondaryIndexes[5]: "KeySchema" Missing required parameter in GlobalSecondaryIndexes[5]: "Projection"
This is what I have
aws dynamodb create-table \
--region=eu-west-2 \
--endpoint-url http://localhost:8000 \
--table-name PBA2 \
--attribute-definitions \
AttributeName=PK,AttributeType=S \
AttributeName=SK,AttributeType=S \
AttributeName=GSI1PK,AttributeType=S \
AttributeName=GSI1SK,AttributeType=S \
AttributeName=GSI2PK,AttributeType=S \
AttributeName=GSI2SK,AttributeType=S \
AttributeName=GSI3PK,AttributeType=S \
AttributeName=GSI3SK,AttributeType=S \
AttributeName=GSI4PK,AttributeType=S \
AttributeName=GSI4SK,AttributeType=S \
AttributeName=GSI5PK,AttributeType=S \
AttributeName=GSI5SK,AttributeType=S \
--key-schema \
AttributeName=PK,KeyType=HASH \
AttributeName=SK,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=10 \
--global-secondary-indexes \
'IndexName=GSI1,KeySchema=[{AttributeName=GSI1PK,KeyType=HASH},{AttributeName=GSI1SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
'IndexName=GSI2,KeySchema=[{AttributeName=GSI2PK,KeyType=HASH},{AttributeName=GSI2SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
'IndexName=GSI3,KeySchema=[{AttributeName=GSI3PK,KeyType=HASH},{AttributeName=GSI3SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
'IndexName=GSI4,KeySchema=[{AttributeName=GSI4PK,KeyType=HASH},{AttributeName=GSI4SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
'IndexName=GSI5,KeySchema=[{AttributeName=GSI5PK,KeyType=HASH},{AttributeName=GSI5SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
ProvisionedThroughput="{ReadCapacityUnits=10,WriteCapacityUnits=10}"
I tried to follow this answer but as you see, I am not getting the result I want. How can I add multiple GSIs?
Upvotes: 0
Views: 1156
Reputation: 929
I finally figure it out:
aws dynamodb create-table \
--region=eu-west-2 \
--endpoint-url http://localhost:8000 \
--table-name PBA2 \
--attribute-definitions \
AttributeName=PK,AttributeType=S \
AttributeName=SK,AttributeType=S \
AttributeName=GSI1PK,AttributeType=S \
AttributeName=GSI1SK,AttributeType=S \
AttributeName=GSI2PK,AttributeType=S \
AttributeName=GSI2SK,AttributeType=S \
AttributeName=GSI3PK,AttributeType=S \
AttributeName=GSI3SK,AttributeType=S \
AttributeName=GSI4PK,AttributeType=S \
AttributeName=GSI4SK,AttributeType=S \
AttributeName=GSI5PK,AttributeType=S \
AttributeName=GSI5SK,AttributeType=S \
--key-schema \
AttributeName=PK,KeyType=HASH \
AttributeName=SK,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=10 \
--global-secondary-indexes \
IndexName=GSI1,KeySchema=["{AttributeName=GSI1PK,KeyType=HASH}","{AttributeName=GSI1SK,KeyType=RANGE}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=10,WriteCapacityUnits=10}" \
IndexName=GSI2,KeySchema=["{AttributeName=GSI2PK,KeyType=HASH}","{AttributeName=GSI2SK,KeyType=RANGE}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=10,WriteCapacityUnits=10}" \
IndexName=GSI3,KeySchema=["{AttributeName=GSI3PK,KeyType=HASH}","{AttributeName=GSI3SK,KeyType=RANGE}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=10,WriteCapacityUnits=10}" \
IndexName=GSI4,KeySchema=["{AttributeName=GSI4PK,KeyType=HASH}","{AttributeName=GSI4SK,KeyType=RANGE}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=10,WriteCapacityUnits=10}" \
IndexName=GSI5,KeySchema=["{AttributeName=GSI5PK,KeyType=HASH}","{AttributeName=GSI5SK,KeyType=RANGE}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=10,WriteCapacityUnits=10}"
Upvotes: 0
Reputation: 78583
You have accidentally supplied ProvisionedThroughput=...
as a 6th GSI.
Instead, it should be an (optional) attribute on each of the first 5 GSIs. Something like this (quote as needed:
IndexName=GSI1,KeySchema=[{AttributeName=GSI1PK,KeyType=HASH},{AttributeName=GSI1SK,KeyType=RANGE}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=10,WriteCapacityUnits=10} \
IndexName=GSI2,KeySchema=[{AttributeName=GSI2PK,KeyType=HASH},{AttributeName=GSI2SK,KeyType=RANGE}],Projection={ProjectionType=ALL},ProvisionedThroughput={ReadCapacityUnits=10,WriteCapacityUnits=10} \
....
Upvotes: 1