Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you add a global secondary index to dynamodb after table has been created?

With an existing dynamodb table, is it possible to modify the table to add a global secondary index? From the dynamodb control panel, it looks like I have to delete the table and create a new one with the global index.

like image 905
user602525 Avatar asked Mar 26 '14 18:03

user602525


People also ask

Can I add GSI to existing table?

To add a global secondary index to an existing table, use the UpdateTable operation with the GlobalSecondaryIndexUpdates parameter. You must provide the following: An index name. The name must be unique among all the indexes on the table.

Can GSI be created after table creation?

Global Secondary Indexes (GSI) enable you to perform more efficient queries. Now, you can add or delete GSIs from your table at any time, instead of just during table creation.

Can you update secondary index DynamoDB?

When you add or update a table item, DynamoDB updates all local secondary indexes that are affected. If the indexed attributes are defined in the table, the local secondary indexes grow too.


1 Answers

Edit (January 2015):

Yes, you can add a global secondary index to a DynamoDB table after its creation; see here, under "Global Secondary Indexes on the Fly".


Old Answer (no longer strictly correct):

No, the hash key, range key, and indexes of the table cannot be modified after the table has been created. You can easily add elements that are not hash keys, range keys, or indexed elements after table creation, though.

From the UpdateTable API docs:

You cannot add, modify or delete indexes using UpdateTable. Indexes can only be defined at table creation time.

To the extent possible, you should really try to anticipate current and future query requirements and design the table and indexes accordingly.

You could always migrate the data to a new table if need be.

like image 190
rpmartz Avatar answered Sep 21 '22 21:09

rpmartz