Bird
0
0

Which of the following is the correct JSON snippet to define a Global Secondary Index (GSI) named "CategoryIndex" with partition key "Category" (HASH) and sort key "Price" (RANGE)?

easy📝 Syntax Q3 of 15
AWS - DynamoDB
Which of the following is the correct JSON snippet to define a Global Secondary Index (GSI) named "CategoryIndex" with partition key "Category" (HASH) and sort key "Price" (RANGE)?
A{ "IndexName": "CategoryIndex", "KeySchema": [ {"AttributeName": "Category", "KeyType": "HASH"} ], "Projection": {"ProjectionType": "ALL"} }
B{ "IndexName": "CategoryIndex", "KeySchema": [ {"AttributeName": "Category", "KeyType": "HASH"}, {"AttributeName": "Date", "KeyType": "RANGE"} ], "Projection": {"ProjectionType": "INCLUDE", "NonKeyAttributes": ["Price"]} }
C{ "IndexName": "CategoryIndex", "KeySchema": [ {"AttributeName": "Category", "KeyType": "HASH"}, {"AttributeName": "Price", "KeyType": "RANGE"} ], "Projection": {"ProjectionType": "ALL"} }
D{ "IndexName": "CategoryIndex", "KeySchema": [ {"AttributeName": "Category", "KeyType": "RANGE"} ], "Projection": {"ProjectionType": "KEYS_ONLY"} }
Step-by-Step Solution
Solution:
  1. Step 1: Understand GSI key schema requirements

    GSI must have a partition key (HASH) and optionally a sort key (RANGE). The correct snippet defines KeySchema with Category (HASH) and Price (RANGE), plus Projection ALL.
  2. Step 2: Check why others fail

    One lacks the sort key Price; another uses Date as sort key instead of Price; the last has only RANGE key without required HASH partition key.
  3. Final Answer:

    Correct GSI definition with HASH and RANGE keys and ALL projection. -> Option C
  4. Quick Check:

    GSI key schema = HASH + optional RANGE [OK]
Quick Trick: GSI needs HASH key; RANGE optional but common [OK]
Common Mistakes:
  • Using RANGE key alone without HASH key
  • Missing required keys in KeySchema
  • Incorrect ProjectionType or missing attributes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes