Search code examples
amazon-web-servicesamazon-dynamodbamazon-dynamodb-local

AWS DynamoDB Local add global secondary index using awscli


Hello I try to execute the following command in order to add a Global Secondary Index to an existing table:

aws dynamodb update-table \
    --region eu-west-1 \
    --endpoint-url http://127.0.0.1:8000/ \
    --table-name ssib_dev_assetsTable \
    --attribute-definitions AttributeName=AssetGroup,AttributeType=S \
    --global-secondary-index-updates  \
    Create="{IndexName=gsi_group,KeySchema=[{AttributeName=AssetGroup,KeyType=HASH}],Projection={ProjectionType=ALL}}" \
    --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=10 \

After + or - 10seconds I have the following response, without any explicit error message. I use https://hub.docker.com/r/cnadiminti/dynamodb-local/ to emulate my db.

An error occurred (InternalFailure) when calling the UpdateTable operation (reached max retries: 9): The request processing has failed because of an unknown error, exception or failure.


Solution

  • The parameter --global-secondary-index-updates should be a valid JSON string, which it is not in your case. It is also missing a mandatory key, ProvisionedThroughput.

    https://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-table.html

    Here goes:

    aws dynamodb update-table \
        --region eu-west-1 \
        --endpoint-url http://127.0.0.1:8000 \
        --table-name ssib_dev_assetsTable \
        --attribute-definitions AttributeName=AssetGroup,AttributeType=S \
        --global-secondary-index-updates '[{"Create":{"IndexName":"gsi_group","KeySchema":[{"AttributeName":"AssetGroup","KeyType":"HASH"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}}]'
    
    By the way, you should probably use the official image instead of some image by some random user docker user: https://hub.docker.com/r/amazon/dynamodb-local/