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.

Answer from rpmartz on Stack Overflow
🌐
AWS
docs.aws.amazon.com › amazon dynamodb › developer guide › working with tables, items, queries, scans, and indexes › improving data access with secondary indexes in dynamodb › using global secondary indexes in dynamodb › managing global secondary indexes in dynamodb
Managing Global Secondary Indexes in DynamoDB - Amazon DynamoDB
When DynamoDB has finished building a global secondary index, the index status changes from CREATING to ACTIVE. To add a global secondary index to an existing table, use the UpdateTable operation with the GlobalSecondaryIndexUpdates parameter.
🌐
Serverless Forums
forum.serverless.com › serverless framework
Dynamodb add GSI to existing table - Serverless Framework - Serverless Forums
November 16, 2018 - I created a table but now want to add a GSI. I add a new item to the AttributeDefinitions and then add in the info to the GlobalSecondaryIndexes. When I start up (offline - sls offline start) I am greeted with: Server…
Discussions

Dynamodb: add GSI to existing Dynamodb table via CDK deploy
A way to use Table.addGlobalSecondaryIndex for existing tables so we can Add an inde to a existing table using the CDK. Use Case I create my DynamoDB tables via the CDK. Now I have to add an index, so I want to ideally update the existin... More on github.com
🌐 github.com
18
January 5, 2021
AWS Cloud Formation - GSI not creating on existing table
Creating a Global Secondary Index (GSI) on an existing DynamoDB table using CloudFormation is possible, but there are some important considerations: If you're trying to modify an existing table that was not originally created by CloudFormation, you'll need to import the table into your CloudFormation stack first. You can't directly modify resources that aren't managed by CloudFormation. When adding ... More on repost.aws
🌐 repost.aws
1
0
November 20, 2024
amazon web services - Populate GSI attributes in Dynamodb if GSI is added on an existing table - Stack Overflow
I have an existing table with all the data, around 1 million records. I needed to add GSI to the table to better query some data. However, with app logic the GSI is being populated only for new rec... More on stackoverflow.com
🌐 stackoverflow.com
Duration estimation for DynamoDB GSI creation on existing table
From the documentation online: "While the resource allocation and backfilling phases are in progress, the index is in the CREATING state. During this time, DynamoDB performs read operations on the table. You are not charged for read operations from the base table to populate the global secondary index. However, you are charged for write operations to populate the newly created global secondary index." My recommendation would be to switch to OnDemand if you want it as fast as possible where cost is not an option. If you want to be patient then I'd recommend just letting the table autoscale with provisioned concurrency. The cost of filling the table is the cost. If you want to avoid throttles which will back pressure throttles to the main table then letting auto scaling handle things is the best approach. I've done this several times on tables multiple order of magnitude larger than what you listed and never had a problem and never really worried about it. More on reddit.com
🌐 r/aws
2
6
September 15, 2021
People also ask

Why is the DynamoDB GSI not showing the item count?
Usually, DynamoDB takes around 6 hours to update the item count of a GSI. So, you will not see the item count get updated immediately.
🌐
dynobase.dev
dynobase.dev › dynamodb-gsi
DynamoDB Global Secondary Index (GSI) - The Ultimate Guide
Can a DynamoDB range key be a GSI key?
Yes. You can use a range key as a GSI.
🌐
dynobase.dev
dynobase.dev › dynamodb-gsi
DynamoDB Global Secondary Index (GSI) - The Ultimate Guide
How many GSIs can be created in DynamoDB?
A single DynamoDB table supports a maximum of 20 global secondary indexes.
🌐
dynobase.dev
dynobase.dev › dynamodb-gsi
DynamoDB Global Secondary Index (GSI) - The Ultimate Guide
Top answer
1 of 3
42

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.

2 of 3
31

Just got an email from Amazon:

Dear Amazon DynamoDB Customer,

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. GSIs can be added via the DynamoDB console or a simple API call. While the GSI is being added or deleted, the DynamoDB table can still handle live traffic and provide continuous service at the provisioned throughput level. To learn more about Online Indexing, please read our blog or visit the documentation page for more technical and operational details.

If you have any questions or feedback about Online Indexing, please email us.

Sincerely, The Amazon DynamoDB Team

🌐
AWS
docs.aws.amazon.com › amazon dynamodb › developer guide › working with tables, items, queries, scans, and indexes › improving data access with secondary indexes in dynamodb › using global secondary indexes in dynamodb › working with global secondary indexes in dynamodb using aws cli
Working with Global Secondary Indexes in DynamoDB using AWS CLI - Amazon DynamoDB
The following example uses the same schema as the previous example, but assumes that the table has already been created and we're adding the GSI later. aws dynamodb update-table \ --table-name GameScores \ --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\"] } } } ]"
🌐
DynamoDB
dynobase.dev › dynamodb-gsi
DynamoDB Global Secondary Index (GSI) - The Ultimate Guide
You can update the GSI of an existing DynamoDB table using the AWS management console or AWS CLI.
🌐
GitHub
github.com › aws › aws-cdk › issues › 12343
Dynamodb: add GSI to existing Dynamodb table via CDK deploy · Issue #12343 · aws/aws-cdk
January 5, 2021 - @aws-cdk/aws-dynamodbRelated to Amazon DynamoDBRelated to Amazon DynamoDBguidanceQuestion that needs advice or information.Question that needs advice or information.response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. ... A way to use Table.addGlobalSecondaryIndex for existing tables so we can Add an inde to a existing table using the CDK.
Author   aws
Find elsewhere
🌐
AWS re:Post
repost.aws › questions › QU6asMifrJQEmncECZYikD6g › aws-cloud-formation-gsi-not-creating-on-existing-table
AWS Cloud Formation - GSI not creating on existing table | AWS re:Post
November 20, 2024 - You can't directly modify resources that aren't managed by CloudFormation. When adding a GSI to an existing table using CloudFormation, you need to update the table's resource definition in your template.
Top answer
1 of 1
3

How you would approach backfilling the table would ultimately depend on the data size.

Small table

If your data size is in low GB's, then you can achieve it quite easily using Lambda/EC2/Local Machine etc....

You would need to Scan or Parallel Scan all the items in the table, filter out the items which do not require updating and then proceed to call UpdateItem on each item in the result set and append the GSI keys.

Large table

If however, you have a large amount of data you may want to use a distributed system such as AWS Glue and Spark. Here, you would either read all the items directly from the table or read from an S3 Export and again obtain the keys which require updating. Then using Sparks forEachPartition to distribute UpdateItem across executors to update items.

Performance vs Cost

As with most services, there is a performance vs cost trade off. If you want to go fast, you'll likely incur more cost. If cost is an important factor for you, then you may want to do things slower. That would entail using a rate limited Scan rather than using Scan/Parallel Scan or even the Glue approach.

Rate limiting can be achieved using the Guava library in Java for example. This would ensure you don't consume too much capacity too quickly.

For larger tables its a little more difficult, as long running processes can die for various reasons, for that reason I would continually checkpoint which data you have read to avoid duplicate work when your restart your process.

Another important cost component is to use provisioned capacity mode when doing any sort of backfilling or data loading. On-demand mode is pay-per-request and for that reason it would not matter how fast or slow you go as you pay for each item read and written. Provisioned capacity mode offers significant cost savings over the alternative.

🌐
Reddit
reddit.com › r/aws › duration estimation for dynamodb gsi creation on existing table
r/aws on Reddit: Duration estimation for DynamoDB GSI creation on existing table
September 15, 2021 -

Hi there,

I need to create a GSI for an existing production table, and have been investigating the costs and duration for the creation itself but I'm not really sure if I'm doing a correct estimation.

Basically, I have a table with 90 million records, with an average size of 0.2kb per record.

From what I've been investigating -> 1 WCU = 1 write of up to 1 KB/s

So, let's round to 100.000.000 records * 0.2kb avg item size = 20.000.000kb to process

Then, I would set 5000 WCU to the GSI for the creation, so it would be 5000kb/s which should process the 20.000.000kb in 1.1h

However, it smells like this estimation is far from reality.

Another doubt is how the attributes affect the duration of the GSI creation? I have 10 non_key_attributes and an "INCLUDE" projection_type.

I appreciate your thoughts on this.

Thanks in advance!

🌐
CloudKatha
cloudkatha.com › home › how to create dynamodb table with global secondary index using cloudformation
How to Create DynamoDB table with Global Secondary Index using CloudFormation - CloudKatha
August 29, 2022 - Either you provide ProvisionedThroughput RCU, WCU values on the base table and GSI both or make BillingMode on the base table to be PAY_PER_REQUEST and don’t specify ProvisionedThroughput anywhere. In this template, we are specifying a table Employee with the primary key as EmployeeId. We are also adding two Global Secondary Indexes named Location-index and Department-index. AWSTemplateFormatVersion: 2010-09-09 Description: AWS CloudFormation Template To Create a DynamoDB With GSI Resources: EmployeeTable: Type: AWS::DynamoDB::Table Properties: TableName: Employee AttributeDefinitions: - Att
🌐
AWS re:Post
repost.aws › knowledge-center › create-gsi-dynamodb
Speed up and monitor the creation of a GSI for a DynamoDB table | AWS re:Post
August 5, 2024 - The required number of write capacity units depends on the table and index size, number of items, and the backfilling time frame that you select. To provision additional write capacity, complete the following steps: Open the DynamoDB console.
🌐
Rahulpnath
rahulpnath.com › blog › dynamodb-global-secondary-index-gsi
Exploring Global Secondary Index: Advanced Querying in DynamoDB From .NET | Rahul Nath
June 21, 2023 - You can only create a Global Secondary Index on an existing table. You cannot create a Local Secondary Index once the table is created. Choose the Create index button for the same dialog to create the GSI on an existing table.
🌐
Medium
medium.com › @jun711.g › create-secondary-indexes-for-aws-dynamodb-to-prevent-scanning-3b210b2764bf
Create Secondary Indexes For AWS DynamoDB to Prevent Scanning | by Jun711 | Medium
August 8, 2019 - Go to AWS DynamoDB console and open up your DynamoDB table. ... After clicking on Create Index button, you will see the following popup to configure an index. An index’s partition key can be of String, Binary or Number type.
🌐
ScyllaDB
scylladb.com › home › dynamodb secondary index
What is a DynamoDB Secondary Index? Definition & FAQs | ScyllaDB
August 7, 2025 - To create a secondary index in ... and can be added to an existing table at any time. Adding a GSI starts a background back‑fill that copies existing items into the index....
🌐
Dynamodbguide
dynamodbguide.com › global secondary indexes
Global Secondary Indexes | DynamoDB, explained.
Only Items with the attribute(s) matching the key schema for your index will be copied into the index, so you may end up with fewer Items in the index than in the underlying table. Imagine we want to keep track of Orders that were returned by our Users. We'll store the date of the return in a ReturnDate attribute. We'll also add a global secondary index with a composite key schema using ReturnDate as the HASH key and OrderId as the RANGE key. ... $ aws dynamodb update-table \ --table-name UserOrdersTable \ --attribute-definitions '[ { "AttributeName": "ReturnDate", "AttributeType": "S" }, { "A
🌐
AWS
docs.aws.amazon.com › amazon dynamodb › developer guide › working with tables, items, queries, scans, and indexes › improving data access with secondary indexes in dynamodb › using global secondary indexes in dynamodb
Using Global Secondary Indexes in DynamoDB - Amazon DynamoDB
When creating a Global Secondary Index (GSI), write operations to the base table can be throttled if the GSI activity resulting from writes to the base table exceeds the GSI's provisioned write capacity. This throttling affects all write operations, from indexing process to potentially disrupting your production workloads. For more information, see Troubleshooting throttling in Amazon DynamoDB. The cost of writing an item to a global secondary index depends on several factors: If you write a new item to the table that defines an indexed attribute, or you update an existing item to define a previously undefined indexed attribute, one write operation is required to put the item into the index.
🌐
Medium
medium.com › @pratikwanjari › getting-started-with-dynamodb-and-global-secondary-indexes-5d864c611ace
Getting Started with DynamoDB and Global Secondary Indexes | by Pratik Wanjari | Medium
January 27, 2025 - Despite this, querying data through a GSI is typically much faster and more efficient than performing a scan on the entire table. Lets add GSI on UserName in our case to make the retrive operation more efficient .Lets name it ‘UserNameIndex’ ... aws dynamodb update-table \ --table-name Operations \ --attribute-definitions \ AttributeName=UserName,AttributeType=S \ --global-secondary-index-updates \ '[{ "Create": { "IndexName": "UserNameIndex", "KeySchema": [ { "AttributeName": "UserName", "KeyType": "HASH" } ], "Projection": { "ProjectionType": "ALL" }, "BillingMode": "PAY_PER_REQUEST" } }]'