🌐
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
Improving data access with secondary indexes in DynamoDB - Amazon DynamoDB
3 weeks ago - When you create an index, you define an alternate key for the index (partition key and sort key). You also define the attributes that you want to be projected, or copied, from the base table into the index. DynamoDB copies these attributes into the index, along with the primary key attributes from the base table.
🌐
TutorialsPoint
tutorialspoint.com › dynamodb › dynamodb_indexes.htm
DynamoDB - Indexes
DynamoDB uses indexes for primary key attributes to improve accesses. They accelerate application accesses and data retrieval, and support better performance by reducing application lag.
Discussions

amazon web services - DynamoDB create index on map or list type - Stack Overflow
I'm trying to add an index to an attribute inside of a map object in DynamoDB and can't seem to find a way to do so. Is this something that is supported or are indexes really only allowed on scalar More on stackoverflow.com
🌐 stackoverflow.com
How to create an item with an index in DynamoDB?
I have been looking everywhere on AWS docs for any information on this and can find absolutely none. The only answer I keep getting everywhere I look is how to query or scan using a secondary index... More on stackoverflow.com
🌐 stackoverflow.com
amazon web services - Can you add a global secondary index to dynamodb after table has been created? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... With an existing dynamodb table, is it possible to modify the table to add a global secondary index? More on stackoverflow.com
🌐 stackoverflow.com
Suggestion for DynamoDB table index usage
What are the access patterns you're trying achieve out of this table? That should be first thing you should spend time on. And without access patterns laid out, it's a good guess that nobody can answer the question. More on reddit.com
🌐 r/aws
17
0
January 6, 2023
People also ask

What is the DynamoDB index cost?
DynamoDB Indexes are free of charge. However, when you're writing data to the table and index is affected by this, it will consume provisioned WCUs for this operation. This means that if you're writing an item to the table with 4 GSIs and that item has 4 attributes which are indexed by these GSIs, you're going to pay x4 for this. For more writing scenarios, head to AWS docs. Moreover, there are also storage considerations: 100 bytes of overhead per index item, size in bytes of the projected attributes (if any) and size of the index key attribute.
🌐
dynobase.dev
dynobase.dev › dynamodb-indexes
DynamoDB Indexes Explained [Local & Global Secondary Index]
What is a Sparse index in DynamoDB?
Sparse Index is a special type of GSI that allows you to index only a subset of the collection by indexing an attribute that is not present on all the items. This technique is useful to quickly query for a set of items that have a specific attribute value, e.g. only rows that have an attribute 'deletedAt' defined.
🌐
dynobase.dev
dynobase.dev › dynamodb-indexes
DynamoDB Indexes Explained [Local & Global Secondary Index]
What is an Inverted index in DynamoDB?
Inverted Index is a GSI that is basically a primary key but inversed - table's _hash key_ becomes inverted index's sort key and table's sort key becomes inverted index's _hash key_.
🌐
dynobase.dev
dynobase.dev › dynamodb-indexes
DynamoDB Indexes Explained [Local & Global Secondary Index]
🌐
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
In a DynamoDB table, each key value must be unique. However, the key values in a global secondary index do not need to be unique. To illustrate, suppose that a game named Comet Quest is especially difficult, with many new users trying but failing to get a score above zero.
🌐
DynamoDB
dynobase.dev › dynamodb-indexes
DynamoDB Indexes Explained [Local & Global Secondary Index]
They allow you to quickly query and lookup items based on not only the primary index attributes, but also attributes of your choice. Secondary Indexes, unlike primary keys, are not required, and they don't have to be unique.
🌐
AWS
docs.aws.amazon.com › amazon dynamodb › developer guide › best practices for designing and architecting with dynamodb › best practices for using secondary indexes in dynamodb › general guidelines for secondary indexes in dynamodb
General guidelines for secondary indexes in DynamoDB - Amazon DynamoDB
As a result, the total size of ... for read and write activity with the table it is indexing. Each table in DynamoDB can have up to 20 global secondary indexes (default quota) and 5 local secondary indexes....
🌐
Secondary Indexes
dynamodbguide.com › secondary indexes
Secondary Indexes | DynamoDB, explained.
Secondary indexes allow you to specify alternate key structures which can be used in Query or Scan operations (but not GetItem operations). In this lesson, we'll discuss the two types of secondary indexes, and we'll cover some basic rules for working with secondary indexes.
🌐
Medium
joudwawad.medium.com › dynamodb-indexes-deep-dive-afe86a1cac48
DynamoDB Indexes Deep Dive | By Joud W. Awad | Medium
March 6, 2025 - The partition key and sort key of the table are always projected into the index; you can project other attributes to support your application’s query requirements. When you query an index, Amazon DynamoDB can access any attribute in the projection as if those attributes were in a table of their own.
Find elsewhere
🌐
DZone
dzone.com › data engineering › databases › indexing in dynamodb
Indexing in DynamoDB
April 11, 2018 - Hello everyone! In this article, I will try to explain indexing in DynamooDb. Amazon DynamoDB provides fast access to items in a table by specifying primary key values.
🌐
GeeksforGeeks
geeksforgeeks.org › dynamodb › aws-dynamodb-working-with-indexes
AWS DynamoDB - Working with Indexes - GeeksforGeeks
March 28, 2023 - Whenever data is modified in the table, the index is automatically modified to reflect changes in the table. We can create and use a secondary index to query faster. While creating a secondary index, we must specify its key attributes—a partition key and a sort key. After the secondary index is created, we can perform operations such as Query or Scan just as we do on the table. DynamoDB doesn't have any query optimizer, so a secondary index is used while you Query it or Scan it.
🌐
Medium
medium.com › @mahimamanik.22 › primary-key-and-secondary-indexes-in-dynamodb-6c658bd3ae15
Primary Key and Secondary Indexes in DynamoDB | by Mahima Manik | Medium
October 4, 2022 - By default, base table’s primary key attributes are always projected into an index. It must be specified during index creation. In summary, here are the differences between LSI and GSI: ... Partition: It is the physical storage internal to DynamoDB, where items with same partition keys but different sort keys are stored.
Top answer
1 of 2
56

Indexes can be built only on top-level JSON attributes. In addition, range keys must be scalar values in DynamoDB (one of String, Number, Binary, or Boolean).

From https://docs.aws.amazon.com/whitepapers/latest/comparing-dynamodb-and-hbase-for-nosql/indexing.html:

Q: Is querying JSON data in DynamoDB any different?

No. You can create a Global Secondary Index or Local Secondary Index on any top-level JSON element. For example, suppose you stored a JSON document that contained the following information about a person: First Name, Last Name, Zip Code, and a list of all of their friends. First Name, Last Name and Zip code would be top-level JSON elements. You could create an index to let you query based on First Name, Last Name, or Zip Code. The list of friends is not a top-level element, therefore you cannot index the list of friends. For more information on Global Secondary Indexing and its query capabilities, see the Secondary Indexes section in this FAQ.

Q: What data types can be indexed?

All scalar data types (Number, String, Binary, and Boolean) can be used for the range key element of the local secondary index key. Set, list, and map types cannot be indexed.

2 of 2
3

I have tried doing hash(str(object)) while I store the object separately. This hash gives me an integer(Number) and I am able to use a secondary index on it. Below is a sample in python, it is important to use a hash function which generates the same hash key every time for the value. So I am using sha1.

# Generate a small integer hash:
import hashlib
def hash_8_digits(source):
    return int(hashlib.sha1(source.encode()).hexdigest(), 16) % (10 ** 8)

The idea is to keep the entire object small while still the entity intact. i.e. rather than serializing and storing the object as string and changing whole way the object is used I am storing a smaller hash value along with the actual list or map.

🌐
AWS
docs.aws.amazon.com › amazon dynamodb › developer guide › best practices for designing and architecting with dynamodb › best practices for using secondary indexes in dynamodb › take advantage of sparse indexes
Take advantage of sparse indexes - Amazon DynamoDB
3 weeks ago - For any item in a table, DynamoDB writes a corresponding index entry only if the index key attributes are present in the item. For a global secondary index, this means the index partition key must be defined on the item, and if the index also has a sort key, that attribute must be present too.
🌐
ScyllaDB
scylladb.com › home › dynamodb secondary index
What is a DynamoDB Secondary Index? Definition & FAQs | ScyllaDB
August 7, 2025 - A DynamoDB secondary index is a feature that lets you query a table using attributes other than the primary key. There are two types: Global Secondary Indexes (GSI), which can use any attribute as the partition and sort key, and Local Secondary ...
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 › managing global secondary indexes in dynamodb
Managing Global Secondary Indexes in DynamoDB - Amazon DynamoDB
DynamoDB allocates the compute and storage resources that are needed for building the index. During the resource allocation phase, the IndexStatus attribute is CREATING and the Backfilling attribute is false. Use the DescribeTable operation to retrieve the status of a table and all of its secondary indexes. While the index is in the resource allocation phase, you can't delete the index or delete its parent table.
🌐
Reddit
reddit.com › r/aws › suggestion for dynamodb table index usage
r/aws on Reddit: Suggestion for DynamoDB table index usage
January 6, 2023 -

Hi, I have loaded a table with the following structure: ID, Name, last name, location, score and some other attributes not relevant to the case.

The problem is to create the most efficient table in terms of cost and reading speed (not many writes will be done to this table). Also, it is expected that the table will be queried several times against the attributes I mentioned earlier. Most likely with one of those or a combination of many of them (e.g., name + last name + location).

In the beginning, I thought it would be good if the ID is the partition key and then create global secondary indexes for each one of the other attributes. However, now that I have loaded the data (10gb) I think I'm going to murder the project's budget with that approach.

Can you suggest me a better way to achieve this please?

Top answer
1 of 3
29
  • DynamoDB is not designed to optimize indexing on set values. Below is a copy of the amazon's relevant documentation (from Improving Data Access with Secondary Indexes in DynamoDB).

The key schema for the index. Every attribute in the index key schema must be a top-level attribute of type String, Number, or Binary. Nested attributes and multi-valued sets are not allowed. Other requirements for the key schema depend on the type of index: For a global secondary index, the hash attribute can be any scalar table attribute. A range attribute is optional, and it too can be any scalar table attribute. For a local secondary index, the hash attribute must be the same as the table's hash attribute, and the range attribute must be a non-key table attribute.

  • Amazon recommends creating a separate one-to-many table for these kind of problems. More info here : Use one to many tables
2 of 3
12

This is a really old post, sorry to revive it, but I'd take a look at "Single Table Design"

Basically, stop thinking about your data as structured data - embrace denormalization

id (Number - primary key ) title (String) created_at (Number - long) tags (StringSet - contains a set of tags say android, ios, etc.,)

Instead of a nosql table with a "header" of this:
id|title|created_at|tags

think of it like this:

pk|sk    |data....
id|id    |{title, created_at}
id|id+tag|{id, tag} <- create one record per tag

You can still return everything by querying for pk=id & sk begins with id and join the tags to the id records in your app logic

and you can use a GSI to project id|id+tag into tag|id which will still require you to write two queries against your data to get items of a given tag (get the ids then get the items), but you won't have to duplicate your data, you wont have to scan and you'll still be able to get your items in one query when your access pattern doesn't rely on tags.

FWIW I'd start by thinking about all of your access patterns, and from there think about how you can structure composite keys and/or GSIs

cheers