AWS Developer Tools Blog
Create, Update, and Delete Global Secondary Indexes Using the Amazon DynamoDB Document API
Amazon DynamoDB recently announced a new feature, online indexing that helps you create and modify global secondary indexes (GSI) after table creation. You can also delete a global secondary index associated with a table at any time. This blog post shows how easy it is to use the Amazon DynamoDB Document API of AWS SDK for Java to perform these operations.
Let’s say your application has a Customer table with CustomerId as the primary key and holds the personal details of a customer.
{ "CustomerId" : 1000, "FirstName" : "John", "LastName" : "Myers", "Gender" : "M", "AddressLine1" : "156th Avenue", "City" : "Redmond", "State" : "WA", "Zip" : "98052" }
You want to create a new global secondary index on the State
attribute that helps you in search operations. You can do this with the following code:
Amazon DynamoDB allows you to modify the provisioned throughput
of a global secondary index at any time after index creation. You can do this with the following code:
You can also delete a global secondary index using the following code:
Do you use the Amazon DynamoDB Document API to access Amazon DynamoDB? Let us know what you think!