dynobase-icon
Dynobase

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

Rafal Wilinski

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: true isn'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.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.