Bird
Raised Fist0
DynamoDBquery~20 mins

Index capacity and cost in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Index Capacity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does a Global Secondary Index (GSI) affect write capacity?

In DynamoDB, when you add a Global Secondary Index (GSI) to a table, how does it impact the write capacity units (WCUs) consumed?

AWrites consume WCUs for the base table, but GSIs consume read capacity units (RCUs) instead.
BWrites only consume WCUs for the base table; GSIs do not affect write capacity.
CWrites to the table consume WCUs for both the base table and the GSI, effectively doubling the write capacity usage.
DWrites consume WCUs only for the GSI, not the base table.
Attempts:
2 left
💡 Hint

Think about how data is duplicated in GSIs.

❓ query_result
intermediate
2:00remaining
Calculate read capacity units for a query on a Local Secondary Index (LSI)

You have a DynamoDB table with 4 KB items. You query a Local Secondary Index (LSI) and retrieve 3 items. How many read capacity units (RCUs) are consumed if you use eventually consistent reads?

A2 RCUs
B6 RCUs
C1 RCUs
D12 RCUs
Attempts:
2 left
💡 Hint

Each 4 KB item read with eventually consistent reads consumes 0.5 RCU.

📝 Syntax
advanced
2:30remaining
Identify the correct syntax to create a GSI with provisioned capacity

Which of the following AWS CLI commands correctly creates a Global Secondary Index (GSI) with provisioned read and write capacity?

DynamoDB
aws dynamodb update-table --table-name Music --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=AlbumTitle,AttributeType=S --global-secondary-index-updates '[{"Create":{"IndexName":"ArtistAlbumIndex","KeySchema":[{"AttributeName":"Artist","KeyType":"HASH"},{"AttributeName":"AlbumTitle","KeyType":"RANGE"}],"Projection":{"ProjectionType":"ALL"},"ProvisionedThroughput":{"ReadCapacityUnits":5,"WriteCapacityUnits":5}}}]'
AThe command is missing the --provisioned-throughput flag outside the GSI definition.
BThe command as shown is correct and will create the GSI with provisioned capacity.
CThe KeySchema must have only one attribute for a GSI, so this command is invalid.
DThe ProjectionType must be KEYS_ONLY for provisioned GSIs, so this command will fail.
Attempts:
2 left
💡 Hint

Check the JSON structure inside the --global-secondary-index-updates parameter.

❓ optimization
advanced
2:30remaining
Optimize read capacity usage for a frequently queried attribute

You have a DynamoDB table with a large number of items. You frequently query by a non-key attribute. Which approach optimizes read capacity usage?

AAdd the attribute as a sort key in the base table and query with a filter expression.
BScan the entire table and filter results on the client side.
CUse a Local Secondary Index (LSI) on that attribute and query it.
DCreate a Global Secondary Index (GSI) on that attribute and query the GSI instead of the base table.
Attempts:
2 left
💡 Hint

Think about how indexes reduce the amount of data scanned.

🔧 Debug
expert
3:00remaining
Diagnose unexpected high write capacity consumption with GSIs

A DynamoDB table has two GSIs. Suddenly, write capacity usage spikes unexpectedly. Which is the most likely cause?

AThe GSIs have large projected attributes causing more data to be written and higher WCUs consumed.
BThe table's read capacity units are too low, causing throttling on writes.
CThe table's partition key was changed, invalidating the GSIs and causing retries.
DThe GSIs are using eventually consistent reads, which double the write capacity usage.
Attempts:
2 left
💡 Hint

Consider how projected attributes affect write costs.

Practice

(1/5)
1. What is the main reason to use indexes in DynamoDB?
easy
A. To speed up query performance by allowing efficient data access
B. To reduce the storage size of the table
C. To automatically backup data
D. To encrypt data at rest

Solution

  1. Step 1: Understand the purpose of indexes

    Indexes in DynamoDB are designed to speed up queries by providing alternate ways to access data efficiently.
  2. Step 2: Eliminate unrelated options

    Options about storage size, backup, and encryption are unrelated to index functionality.
  3. Final Answer:

    To speed up query performance by allowing efficient data access -> Option A
  4. Quick Check:

    Indexes improve query speed = B [OK]
Hint: Indexes speed queries, not reduce storage or backup [OK]
Common Mistakes:
  • Thinking indexes reduce storage cost
  • Confusing indexes with backup features
  • Assuming indexes encrypt data
2. Which of the following is the correct way to specify a Global Secondary Index (GSI) in a DynamoDB table creation JSON?
easy
A. { "LocalSecondaryIndexes": [ { "IndexName": "MyGSI", "KeySchema": [ {"AttributeName": "UserId", "KeyType": "HASH"} ], "Projection": {"ProjectionType": "ALL"} } ] }
B. { "GlobalSecondaryIndexes": [ { "IndexName": "MyGSI", "KeySchema": [ {"AttributeName": "UserId", "KeyType": "HASH"} ], "Projection": {"ProjectionType": "ALL"}, "ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5} } ] }
C. { "GlobalSecondaryIndexes": { "IndexName": "MyGSI" } }
D. { "Indexes": [ { "Name": "MyGSI" } ] }

Solution

  1. Step 1: Identify correct GSI syntax

    Global Secondary Indexes require an array under "GlobalSecondaryIndexes" with full details: IndexName, KeySchema, Projection, and ProvisionedThroughput.
  2. Step 2: Compare options

    { "GlobalSecondaryIndexes": [ { "IndexName": "MyGSI", "KeySchema": [ {"AttributeName": "UserId", "KeyType": "HASH"} ], "Projection": {"ProjectionType": "ALL"}, "ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5} } ] } correctly uses "GlobalSecondaryIndexes" as an array with all required fields. Others use wrong keys or incomplete structures.
  3. Final Answer:

    { "GlobalSecondaryIndexes": [ { "IndexName": "MyGSI", "KeySchema": [ {"AttributeName": "UserId", "KeyType": "HASH"} ], "Projection": {"ProjectionType": "ALL"}, "ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5} } ] } -> Option B
  4. Quick Check:

    GSI syntax requires array with full details = A [OK]
Hint: GSIs need full details in GlobalSecondaryIndexes array [OK]
Common Mistakes:
  • Using LocalSecondaryIndexes instead of GlobalSecondaryIndexes
  • Providing object instead of array for GSIs
  • Omitting ProvisionedThroughput for GSIs
3. Given a DynamoDB table with a provisioned write capacity of 10 units and a Global Secondary Index (GSI) with 5 write capacity units, what is the total write capacity units consumed when writing one item to the table and the GSI?
medium
A. 5 units
B. 10 units
C. 15 units
D. 20 units

Solution

  1. Step 1: Understand write capacity consumption

    Writing one item consumes write capacity units on the main table plus on each index that is updated.
  2. Step 2: Add main table and GSI write units

    Main table uses 10 units, GSI uses 5 units, total = 10 + 5 = 15 units.
  3. Final Answer:

    15 units -> Option C
  4. Quick Check:

    Total write capacity = main + GSI = 15 [OK]
Hint: Add main table and index write units for total cost [OK]
Common Mistakes:
  • Counting only main table write units
  • Counting only GSI write units
  • Multiplying instead of adding capacities
4. You notice your DynamoDB table's write capacity is being exceeded even though your application writes only a few items per second. Which of the following is the most likely cause related to indexes?
medium
A. You have a Global Secondary Index with high write capacity units causing extra cost
B. You forgot to create any indexes
C. Your table has no read capacity units set
D. You are using Local Secondary Indexes which do not affect write capacity

Solution

  1. Step 1: Analyze write capacity usage

    Writes to the table also consume write capacity on GSIs, increasing total usage.
  2. Step 2: Identify cause of exceeded capacity

    If GSIs have high write capacity or many writes, they can cause capacity to be exceeded even if main table writes are low.
  3. Final Answer:

    You have a Global Secondary Index with high write capacity units causing extra cost -> Option A
  4. Quick Check:

    GSIs increase write capacity usage = C [OK]
Hint: Check GSIs for hidden write capacity usage [OK]
Common Mistakes:
  • Assuming no indexes means no extra capacity
  • Confusing read and write capacity units
  • Thinking Local Secondary Indexes increase write capacity
5. You want to optimize costs for a DynamoDB table with a Global Secondary Index (GSI). The table has 20 write capacity units and the GSI has 10 write capacity units. If your application writes 5 items per second, how can you reduce costs without affecting query performance on the GSI?
hard
A. Disable the table's write capacity units
B. Remove the GSI to save all index costs
C. Increase the table write capacity units to 30
D. Reduce the GSI write capacity units to 5 and enable auto scaling

Solution

  1. Step 1: Understand cost drivers

    Write capacity units on both table and GSI affect cost. Reducing GSI units lowers cost but must still handle write load.
  2. Step 2: Apply auto scaling and adjust capacity

    Reducing GSI write units to match actual writes (5) and enabling auto scaling balances cost and performance.
  3. Final Answer:

    Reduce the GSI write capacity units to 5 and enable auto scaling -> Option D
  4. Quick Check:

    Lower GSI units + auto scaling = cost optimization [OK]
Hint: Match GSI capacity to writes and use auto scaling [OK]
Common Mistakes:
  • Removing GSI and losing query performance
  • Increasing table capacity unnecessarily
  • Disabling write capacity causing failures
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard