Index projection types decide which data from your table is copied into an index. This helps you get data faster and use less storage.
Index projection types (ALL, KEYS_ONLY, INCLUDE) in 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.
Projection: ProjectionType: ALL
Projection: ProjectionType: KEYS_ONLY
Projection: ProjectionType: INCLUDE NonKeyAttributes: ["Name", "Age"]
This creates a table Users and a global secondary index EmailIndex that copies all attributes from the table.
CREATE TABLE Users ( UserID STRING, Email STRING, Name STRING, Age NUMBER, PRIMARY KEY (UserID) ); CREATE GLOBAL SECONDARY INDEX EmailIndex ON Users(Email) PROJECTION ALL;
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.
ALL copies all attributes to the index.
KEYS_ONLY copies only the keys.
INCLUDE copies keys plus specific extra attributes you choose.
Practice
all attributes from the base table to the index?Solution
Step 1: Understand projection types
ALL copies every attribute from the base table to the index.Step 2: Compare with other types
KEYS_ONLY copies only keys; INCLUDE copies keys plus selected attributes.Final Answer:
ALL -> Option AQuick Check:
ALL = copies all attributes [OK]
- Confusing INCLUDE with ALL
- Thinking KEYS_ONLY copies all attributes
- Assuming PARTIAL is a valid projection type
Solution
Step 1: Recall correct syntax for KEYS_ONLY
The projection type must be exactly "KEYS_ONLY" in quotes.Step 2: Eliminate incorrect options
ALL and INCLUDE are valid but not KEYS_ONLY; "KEYS" is invalid syntax.Final Answer:
"ProjectionType": "KEYS_ONLY" -> Option BQuick Check:
KEYS_ONLY syntax = "KEYS_ONLY" [OK]
- Using "KEYS" instead of "KEYS_ONLY"
- Confusing INCLUDE with KEYS_ONLY syntax
- Omitting quotes around projection type
id, name, age, and city, and a Global Secondary Index (GSI) with projection type INCLUDE and non-key attributes age and city, which attributes will be available in the index?Solution
Step 1: Identify keys and included attributes
Index always includes keys; INCLUDE adds specified non-key attributes.Step 2: Determine which attributes are keys
Assumingidis the partition key,nameis not a key.Step 3: Combine keys and included attributes
Index hasid(key), plusageandcity(included).Final Answer:
id,age, andcity-> Option AQuick Check:
INCLUDE = keys + chosen attributes [OK]
- Including non-key attributes not specified in INCLUDE
- Assuming all attributes are included
- Confusing keys with non-key attributes
Solution
Step 1: Understand INCLUDE projection requirements
INCLUDE requires specifying at least one non-key attribute.Step 2: Check behavior when no attributes specified
Omitting non-key attributes causes a validation error during index creation.Final Answer:
The index creation will fail with a validation error. -> Option DQuick Check:
INCLUDE needs attributes; missing causes error [OK]
- Assuming INCLUDE defaults to ALL attributes
- Thinking index silently defaults to KEYS_ONLY
- Ignoring validation errors on index creation
email and retrieve phone and address attributes quickly. Which projection type should you choose?Solution
Step 1: Understand storage cost vs attribute needs
ALL copies all attributes but costs more storage; KEYS_ONLY copies only keys.Step 2: Identify needed attributes for queries
You needemailas key andphone,addressfor quick retrieval.Step 3: Choose INCLUDE projection with needed attributes
INCLUDE lets you copy keys plus onlyphoneandaddress, saving storage.Final Answer:
INCLUDE withphoneandaddress-> Option CQuick Check:
INCLUDE = keys + needed attributes saves cost [OK]
- Choosing ALL and increasing storage unnecessarily
- Using KEYS_ONLY and missing needed attributes
- Including only email but not phone or address
Ready to prove it?
Pass the test and this pattern moves unknown
