Index projection types decide which data from your table is copied into an index. This helps you get data faster and use less storage.
0
0
Index projection types (ALL, KEYS_ONLY, INCLUDE) in DynamoDB
Introduction
When you want to speed up queries by having needed data in the index.
When you want to save storage space by copying only some attributes.
When you want to get only the keys from the table without extra data.
When you want to include specific extra attributes in the index for quick access.
When you want to reduce read costs by limiting data returned from the index.
Syntax
DynamoDB
Projection: ProjectionType: ALL | KEYS_ONLY | INCLUDE NonKeyAttributes: ["attribute1", "attribute2", ...] # Only with INCLUDE
ALL copies all table attributes to the index.
KEYS_ONLY copies only the primary key attributes.
INCLUDE copies the primary keys plus specific extra attributes you list.
Examples
This copies every attribute from the table into the index.
DynamoDB
Projection: ProjectionType: ALL
This copies only the primary key attributes (partition key and sort key) into the index.
DynamoDB
Projection: ProjectionType: KEYS_ONLY
This copies the primary keys plus the "Name" and "Age" attributes into the index.
DynamoDB
Projection: ProjectionType: INCLUDE NonKeyAttributes: ["Name", "Age"]
Sample Program
This creates a table Users and a global secondary index EmailIndex that copies all attributes from the table.
DynamoDB
CREATE TABLE Users ( UserID STRING, Email STRING, Name STRING, Age NUMBER, PRIMARY KEY (UserID) ); CREATE GLOBAL SECONDARY INDEX EmailIndex ON Users(Email) PROJECTION ALL;
OutputSuccess
Important Notes
Using ALL projection makes queries easier but uses more storage.
KEYS_ONLY projection saves space but you get only keys, so you may need to fetch full data separately.
INCLUDE projection is a good balance: you pick only needed extra attributes to include.
Summary
ALL copies all attributes to the index.
KEYS_ONLY copies only the keys.
INCLUDE copies keys plus specific extra attributes you choose.