Question: Can a DynamoDB range key be a GSI key?

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Answer
Yes. The attribute that serves as your table's sort key (the older name is range key) can be the partition key or the sort key of a global secondary index (GSI). Any top-level String, Number or Binary attribute can be a GSI key attribute, including the table's own key attributes, and GSI keys don't have to be unique.
The most common use is the inverted index: a GSI whose partition key is the table's sort key and whose sort key is the table's partition key. In a table where an item with PK = USER#alice and SK = GROUP#admins means "alice belongs to admins", the table answers "which groups is alice in?" and the inverted GSI answers "who is in admins?"
aws dynamodb update-table \ --table-name AppTable \ --attribute-definitions AttributeName=PK,AttributeType=S AttributeName=SK,AttributeType=S \ --global-secondary-index-updates '[{"Create":{"IndexName":"InvertedIndex","KeySchema":[{"AttributeName":"SK","KeyType":"HASH"},{"AttributeName":"PK","KeyType":"RANGE"}],"Projection":{"ProjectionType":"ALL"}}}]'
That command works as written for an on-demand table. For a provisioned table, add ProvisionedThroughput inside Create.
Things to keep in mind:
- Reads from a GSI are eventually consistent.
ConsistentRead: trueisn't supported on global secondary indexes. - Every item has the table's sort key, so an index keyed on it contains every item. An index on an attribute that only some items carry is sparse and holds just those items.
- A GSI can also use a multi-attribute key schema. Check the current GSI documentation before choosing between that feature and concatenated attributes.
- A local secondary index is different: it must use the table's partition key, can only change the sort key, and can only be defined when you create the table.
DynamoDB GSI covers projections and costs, and DynamoDB sort key explains how sort keys order items.
Source: AWS DynamoDB documentation.
Other Common DynamoDB FAQ (with Answers)
- Are DynamoDB table names globally unique?
- Can DynamoDB have null values?
- Is DynamoDB based on MongoDB?
- Does DynamoDB support load balancing?
- How do you access DynamoDB from outside AWS?
- Can Power BI connect to DynamoDB?
- Is DynamoDB a relational database?
- How to access DynamoDB from EC2?
- Can DynamoDB trigger AWS Step Functions?
- Can DynamoDB store images?
- Can DynamoDB store blob data?
- Is DynamoDB HIPAA compliant?
- How to track changes to items in DynamoDB?
- How do you create an index in DynamoDB?
- How is data stored in DynamoDB?
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
- SSH GUI Client
- Chat With Cloud
- MongoDB GUI Client
- AWS Cost Monitoring
- DynamoDB Query Builder
- DynamoDB Code Examples
- DynamoDB Node.js Queries
- DynamoDB JSON Converter
- DynamoDB UUID Generator
- DynamoDB Local Admin GUI
- DynamoDB Pricing Calculator
- DynamoDB Single-Table Design
- Best DynamoDB GUI Clients
- Dynobase vs DynoTable