0
0
DynamoDBquery~20 mins

Creating GSI in DynamoDB - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GSI Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is a Global Secondary Index (GSI) in DynamoDB?

Which statement best describes a Global Secondary Index (GSI) in DynamoDB?

AA GSI is a local index that uses the same partition key as the base table but a different sort key.
BA GSI is an index with a partition key and optional sort key that can be different from the base table's keys, allowing queries on non-key attributes.
CA GSI is a backup of the entire table stored in a different region for disaster recovery.
DA GSI automatically duplicates all data from the base table without any key differences.
Attempts:
2 left
💡 Hint

Think about how GSIs let you query data differently than the main table keys.

query_result
intermediate
2:00remaining
Querying a DynamoDB table using a GSI

Given a DynamoDB table Orders with a GSI named CustomerIndex that has CustomerId as the partition key, what will be the output of the following query?

aws dynamodb query \
  --table-name Orders \
  --index-name CustomerIndex \
  --key-condition-expression "CustomerId = :cid" \
  --expression-attribute-values '{":cid":{"S":"C123"}}'

Assume the table has these items:

  • {OrderId: "O1", CustomerId: "C123", Amount: 100}
  • {OrderId: "O2", CustomerId: "C456", Amount: 200}
  • {OrderId: "O3", CustomerId: "C123", Amount: 150}
A[{"OrderId": "O1", "CustomerId": "C123", "Amount": 100}, {"OrderId": "O3", "CustomerId": "C123", "Amount": 150}]
B[{"OrderId": "O2", "CustomerId": "C456", "Amount": 200}]
C[]
DSyntax error due to missing sort key in query
Attempts:
2 left
💡 Hint

The query uses the GSI to find all orders for CustomerId 'C123'.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in GSI creation

Which option contains a syntax error when creating a GSI in a DynamoDB table using AWS CLI?

aws dynamodb update-table \
  --table-name Products \
  --attribute-definitions AttributeName=Category,AttributeType=S, AttributeName=Price,AttributeType=N \
  --global-secondary-index-updates '[{"Create":{"IndexName":"CategoryPriceIndex","KeySchema":[{"AttributeName":"Category","KeyType":"HASH"},{"AttributeName":"Price","KeyType":"RANGE"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}}]'
AProvisionedThroughput keys should be strings, not numbers
BIncorrect KeyType value 'RANGE' should be 'SORT'
CMissing comma between attribute definitions
DProjectionType 'ALL' is invalid
Attempts:
2 left
💡 Hint

Check the attribute definitions syntax carefully.

optimization
advanced
1:30remaining
Optimizing GSI throughput settings

You have a GSI on a DynamoDB table with heavy read traffic but low write traffic. Which option optimizes cost while maintaining performance?

ASet ReadCapacityUnits high and WriteCapacityUnits low in ProvisionedThroughput for the GSI
BSet both ReadCapacityUnits and WriteCapacityUnits to high values
CSet ReadCapacityUnits low and WriteCapacityUnits high
DUse On-Demand mode for the GSI to avoid capacity settings
Attempts:
2 left
💡 Hint

Think about which capacity units affect read and write costs.

🔧 Debug
expert
2:00remaining
Why does querying a GSI return no results?

You created a GSI on a DynamoDB table with OrderDate as the partition key. After inserting items, querying the GSI returns no results. What is the most likely cause?

ADynamoDB GSIs do not support queries, only scans
BThe GSI was created with the wrong provisioned throughput settings
CThe query syntax is incorrect and missing the sort key condition
DThe items do not have the <code>OrderDate</code> attribute, so they are not indexed in the GSI
Attempts:
2 left
💡 Hint

Remember how DynamoDB indexes items in GSIs.