🌐
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
1 month ago - DynamoDB supports two types of secondary indexes: Global secondary index — An index with a partition key and a sort key that can be different from those on the base table. A global secondary index is considered "global" because queries on the index can span all of the data in the base table, ...
🌐
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 an application writes an item to a table, DynamoDB automatically copies the correct subset of attributes to any global secondary indexes in which those attributes should appear. Your AWS account is charged for storage of the item in the base table and also for storage of attributes in any global secondary indexes on that table.
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
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
ELI5: Indexing in DynamoDB
I know that a Table in DynamoDB can be stored across multiple partitions. I know that an index is meant to speed up database query operations when… More on reddit.com
🌐 r/aws
3
13
December 3, 2019
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 › amazon dynamodb: how it works › from sql to nosql › managing indexes › creating an index
Creating an index - Amazon DynamoDB
August 19, 2022 - CREATE INDEX GenreAndPriceIndex ON Music (genre, price); In DynamoDB, you can create and use a secondary index for similar purposes.
🌐
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....
🌐
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 › local secondary indexes
Local secondary indexes - Amazon DynamoDB
When an application writes an item to a table, DynamoDB automatically copies the correct subset of attributes to any local secondary indexes in which those attributes should appear. Your AWS account is charged for storage of the item in the base table and also for storage of attributes in any local secondary indexes on that table.
🌐
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
Best practices for using secondary indexes in DynamoDB - Amazon DynamoDB
General guidelines for secondary indexes in DynamoDB · Use indexes efficiently · Choose projections carefully · Optimize frequent queries to avoid fetches · Be aware of item-collection size limits when creating local secondary indexes · Take advantage of sparse indexes ·
Find elsewhere
🌐
AWS
aws.amazon.com › blogs › database › multi-key-support-for-global-secondary-index-in-amazon-dynamodb
Multi-key support for Global Secondary Index in Amazon DynamoDB | AWS Database Blog
November 20, 2025 - Amazon DynamoDB has announced support for up to 8 attributes in composite keys for Global Secondary Indexes (GSIs). Now, you can specify up to four partition keys and four sort keys to identify items as part of a GSI, allowing you to query data ...
🌐
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.
🌐
DynamoDB
dynobase.dev › dynamodb-indexes
DynamoDB Indexes Explained [Local & Global Secondary Index]
Still using AWS console to work with DynamoDB? 🙈 Time to 10x your DynamoDB productivity with Dynobase [learn more] What makes DynamoDB so much more than just a simple Key-Value store is the secondary indexes. They allow you to quickly query and lookup items based on not only the primary index attributes, but also attributes of your choice.
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
1 month 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.
🌐
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: java
Working with Global Secondary Indexes: Java - Amazon DynamoDB
The following Java code example creates a table to hold information about weather data. The partition key is Location and the sort key is Date. A global secondary index named PrecipIndex allows fast access to precipitation data for various locations. The following are the steps to create a table with a global secondary index, using the DynamoDB document API.
🌐
AWS
docs.aws.amazon.com › amazon dynamodb › developer guide › getting started with dynamodb › step 7: query the global secondary index
Step 7: Query the global secondary index - Amazon DynamoDB
June 21, 2021 - You query the global secondary index through the DynamoDB API by using query and providing the index name. ... aws dynamodb query \ --table-name Music \ --index-name AlbumTitle-index \ --key-condition-expression "AlbumTitle = :name" \ --expression-attribute-values '{":name":{"S":"Somewhat Famous"}}'
🌐
AWS
sdk.amazonaws.com › java › api › latest › software › amazon › awssdk › enhanced › dynamodb › DynamoDbIndex.html
DynamoDbIndex (AWS SDK for Java - 2.42.10)
Scans the table against a secondary index and retrieves all items using default settings. The result is accessed through iterable pages (see Page) in an interactive way; each time a result page is retrieved, a scan call is made to DynamoDb to get those entries.
🌐
AWS
docs.aws.amazon.com › amazon dynamodb › developer guide › amazon dynamodb: how it works › core components of amazon dynamodb
Core components of Amazon DynamoDB - Amazon DynamoDB
The term range attribute derives from the way DynamoDB stores items with the same partition key physically close together, in sorted order by the sort key value. Each primary key attribute must be a scalar (meaning that it can hold only a single value). The only data types allowed for primary key attributes are string, number, or binary. There are no such restrictions for other, non-key attributes. You can create one or more secondary indexes on a table.
🌐
Caylent
caylent.com › blog › best-practices-for-secondary-indexes-with-dynamodb
Best Practices for Secondary Indexes with Amazon DynamoDB | Caylent
This is a great pattern for leaderboards or for finding most recently updated as you can rely on DynamoDB to handle the deletion and re-creation necessary to re-sort your items. We learned about overloading your secondary indexes to reduce the total number of indexes on your table. And finally, we saw how sparse indexes can enable specialized access patterns by providing targeted filters on your table. ... Founded in 2013, Trek10 helped organizations migrate to and maximize the value of AWS by designing, building, and supporting cloud-native workloads with deep technical expertise.
🌐
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?