Bird
0
0

Given the following code snippet using Boto3 resource:

medium📝 query result Q13 of 15
DynamoDB - with AWS SDK
Given the following code snippet using Boto3 resource:
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')
response = table.get_item(Key={'UserId': '123'})
print(response['Item']['Name'])
What will this code print if the item exists with Name 'Alice'?
A123
BNone
CKeyError
DAlice
Step-by-Step Solution
Solution:
  1. Step 1: Understand the get_item call on resource Table

    The get_item method returns a dictionary with an 'Item' key containing the requested item if it exists.
  2. Step 2: Access the 'Name' attribute from the returned item

    The code prints response['Item']['Name'], which will be 'Alice' if the item exists with that attribute.
  3. Final Answer:

    Alice -> Option D
  4. Quick Check:

    response['Item']['Name'] = Alice [OK]
Quick Trick: get_item returns dict with 'Item' key holding data [OK]
Common Mistakes:
MISTAKES
  • Assuming response is just the item dict
  • Forgetting to check 'Item' key
  • Confusing client and resource response formats

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes