0

I am trying to add a GSI to an existing table on dynamo DB on local. I downloaded the last version(2.5.1) and run ti with:

`java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -port 8001

Creatiing a table works fine:

aws dynamodb create-table  
--endpoint-url http://localhost:8001    
--table-name GameScores2     
--attribute-definitions AttributeName=GameTitle,AttributeType=S  AttributeName=UserId,AttributeType=S    
--key-schema AttributeName=UserId,KeyType=HASH AttributeName=GameTitle,KeyType=RANGE     
--provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5

But when i try to create a GSI, just like in the amazon docs says:

aws dynamodb update-table     --endpoint-url http://localhost:8001     --table-name GameScores2     --attribute-definitions AttributeName=TopScore,AttributeType=N      --global-secondary-index-updates         "[                                                                                                                                                                  
            {
                \"Create\": {
                    \"IndexName\": \"GameTitleIndex\",
                    \"KeySchema\": [{\"AttributeName\":\"GameTitle\",\"KeyType\":\"HASH\"},
                                    {\"AttributeName\":\"TopScore\",\"KeyType\":\"RANGE\"}],
                    \"Projection\":{
                        \"ProjectionType\":\"INCLUDE\",
                        \"NonKeyAttributes\":[\"UserId\"]
                    }
                }
            }
        ]"

Always get the error 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.

I've searched all over internet but as far as I can see the syntax is ok, the bd is running, I have the last version...

Any idea of what can be happening?

Thanks.

If try to create the BD directly with the GSI if works without error. But I need to update and existing BD.

2
  • Can you define what bd means? Commented Jul 10 at 7:48
  • Sorry, i meant a table. If i create a table with the gsi on its definition, i works perfectly. But if i create the table without the gsi and try to add it later, doesnt works.
    – Tesouro
    Commented Jul 10 at 9:15

1 Answer 1

0

Using the latest version of DynamoDB Local from Docker 2.5.2 this works with no issue:

aws dynamodb create-table \
    --table-name MusicCollection \
    --attribute-definitions AttributeName=pk,AttributeType=S AttributeName=sk,AttributeType=S \
    --key-schema AttributeName=pk,KeyType=HASH AttributeName=sk,KeyType=RANGE \
    --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
    --tags Key=Owner,Value=blueTeam \
    --endpoint-url http://localhost:8000

Then:

aws dynamodb update-table \
  --table-name MusicCollection \
  --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=AlbumTitle,AttributeType=S \
  --global-secondary-index-updates \
  "[{\"Create\":{\"IndexName\": \"ArtistIndex\",\"KeySchema\":[{\"AttributeName\":\"Artist\",\"KeyType\":\"HASH\"},{\"AttributeName\":\"AlbumTitle\",\"KeyType\":\"RANGE\"}],\"Projection\":{\"ProjectionType\":\"ALL\"},\"ProvisionedThroughput\":{\"ReadCapacityUnits\":5,\"WriteCapacityUnits\":5}}}]" \
  --endpoint-url http://localhost:8000

Finally:

aws dynamodb describe-table --table-name MusicCollection --endpoint-url http://localhost:8000
{
    "Table": {
        "AttributeDefinitions": [
            {
                "AttributeName": "Artist",
                "AttributeType": "S"
            },
            {
                "AttributeName": "sk",
                "AttributeType": "S"
            },
            {
                "AttributeName": "pk",
                "AttributeType": "S"
            },
            {
                "AttributeName": "AlbumTitle",
                "AttributeType": "S"
            }
        ],
        "TableName": "MusicCollection",
        "KeySchema": [
            {
                "AttributeName": "pk",
                "KeyType": "HASH"
            },
            {
                "AttributeName": "sk",
                "KeyType": "RANGE"
            }
        ],
        "TableStatus": "ACTIVE",
        "CreationDateTime": 1720619297.76,
        "ProvisionedThroughput": {
            "LastIncreaseDateTime": 0.0,
            "LastDecreaseDateTime": 0.0,
            "NumberOfDecreasesToday": 0,
            "ReadCapacityUnits": 5,
            "WriteCapacityUnits": 5
        },
        "TableSizeBytes": 0,
        "ItemCount": 0,
        "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/MusicCollection",
        "GlobalSecondaryIndexes": [
            {
                "IndexName": "ArtistIndex",
                "KeySchema": [
                    {
                        "AttributeName": "Artist",
                        "KeyType": "HASH"
                    },
                    {
                        "AttributeName": "AlbumTitle",
                        "KeyType": "RANGE"
                    }
                ],
                "Projection": {
                    "ProjectionType": "ALL"
                },
                "IndexStatus": "ACTIVE",
                "ProvisionedThroughput": {
                    "ReadCapacityUnits": 5,
                    "WriteCapacityUnits": 5
                },
                "IndexSizeBytes": 0,
                "ItemCount": 0,
                "IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/MusicCollection/index/ArtistIndex"
            }
        ],
        "DeletionProtectionEnabled": false
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.