0
0
DynamoDBquery~20 mins

GetItem (reading single item) in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DynamoDB GetItem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this GetItem query?

Given a DynamoDB table Users with primary key UserID, what will be the output of this GetItem operation?

{
  TableName: "Users",
  Key: { "UserID": { "S": "123" } }
}

Assume the item with UserID "123" exists and has attributes Name: "Alice" and Age: 30.

DynamoDB
const params = {
  TableName: "Users",
  Key: { "UserID": { "S": "123" } }
};

// Assume dynamodbClient.getItem(params) returns the item
A{"Item": {"UserID": "123", "Name": "Alice", "Age": 30}}
B{"Item": {"UserID": {"S": "123"}, "Name": {"S": "Alice"}, "Age": {"N": "30"}}}
C{"Items": [{"UserID": {"S": "123"}, "Name": {"S": "Alice"}, "Age": {"N": "30"}}]}
D{"Item": null}
Attempts:
2 left
💡 Hint

Remember DynamoDB returns attribute values with their types.

📝 Syntax
intermediate
2:00remaining
Which GetItem request syntax is valid?

Which of the following DynamoDB GetItem request objects is syntactically correct?

A{ TableName: "Products", Key: { "ProductID": { "S": "001" } } }
B{ TableName: "Products", Key: { ProductID: "001" } }
C{ TableName: "Products", Key: { "ProductID": "001" } }
D{ TableName: "Products", Key: { ProductID: { S: 001 } } }
Attempts:
2 left
💡 Hint

Check how DynamoDB expects attribute values to be typed.

optimization
advanced
2:00remaining
How to optimize a GetItem request to return only specific attributes?

You want to get only the Name attribute from a DynamoDB item with UserID "789". Which GetItem request achieves this efficiently?

A{ TableName: "Users", Key: { "UserID": { "S": "789" } } }
B{ TableName: "Users", Key: { "UserID": { "S": "789" } }, ProjectionExpression: "UserID, Name" }
C{ TableName: "Users", Key: { "UserID": { "S": "789" } }, ProjectionExpression: "Name" }
D{ TableName: "Users", Key: { "UserID": { "S": "789" } }, AttributesToGet: ["Name"] }
Attempts:
2 left
💡 Hint

Use the recommended way to specify attributes to return in GetItem.

🔧 Debug
advanced
2:00remaining
Why does this GetItem request return no item?

Consider this GetItem request:

{
  TableName: "Orders",
  Key: { "OrderID": { "N": 1001 } }
}

The item with OrderID 1001 exists, but the response returns Item: null. Why?

AThe number value must be passed as a string, e.g., { "N": "1001" }.
BThe key attribute value should be a string, not a number.
CThe table name is incorrect, causing no match.
DGetItem cannot query numeric keys.
Attempts:
2 left
💡 Hint

Check how DynamoDB expects number attribute values in requests.

🧠 Conceptual
expert
2:00remaining
What happens if you call GetItem with a non-existent key?

If you call DynamoDB's GetItem with a key that does not exist in the table, what will the response contain?

AThe response returns an item with all attributes set to null.
BThe response throws a <code>ResourceNotFoundException</code> error.
CThe response returns an empty object <code>{}</code> with no <code>Item</code> key.
DThe response contains <code>Item: null</code> indicating no matching item.
Attempts:
2 left
💡 Hint

Think about how DynamoDB signals no matching item found.