1
votes

How do I use the AWS command line interface to update a pre-existing global secondary index on a DynamoDB table?
I want to increase the provisioned throughput read and write capacity.

I can't find this information in the AWS documentation. Well, I found it for the Java SDK, but I want to do this using the command line interface.

2
Also, tried to post this question initially on AWS's own forums, but wasn't allowed because I have to wait several hours after account creation :-/osullic

2 Answers

3
votes

Command without region attribute:-

Please update the table name in the command accordingly.

aws dynamodb update-table --table-name Movies --global-secondary-index-updates file://update-gsi.json

Command with region attribute:-

Please specify the table in which you have created the DynamoDB table

aws dynamodb update-table --table-name Movies --global-secondary-index-updates file://update-gsi.json --region us-east-1

Json file sample - "update-gsi.json" :-

Please update the index name and values accordingly.

[{
    "Update": {
        "IndexName": "Movies_Gsi",
        "ProvisionedThroughput": {
            "ReadCapacityUnits": 150,
            "WriteCapacityUnits": 150
        }
    }
}]

Command execution:-

Navigate to file path and execute the aws command (or) you may need to specify the full file path in command

2
votes

Just want to add one more way of updating GSI. Like @notionquest has already told you how to do that.

In his case you will have to put things into a separate file and then you will have to have read access to read in the values, seems like a little overhead. Even, I did the same thing when I found out this answer.

But after some hit and trial, I came up with little variation of it; where we can straightly pass the GSI's modification values right from CLI.

Look at the code below:

aws dynamodb update-table --table-name [Your Table's Name] \
                      --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
                      --global-secondary-index-updates '[{
                            "Update": {
                                "IndexName": "[Your GSI's Name]",
                                "ProvisionedThroughput": {
                                    "ReadCapacityUnits": 5,
                                    "WriteCapacityUnits": 5
                                }
                           }
                        }]'

One more thing, I am updating table's throughput and along with the GSI's throughput.