0
0
DynamoDBquery~20 mins

Boto3 (Python) client vs resource in DynamoDB - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Boto3 DynamoDB Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference in method usage between client and resource
Which statement correctly describes how you would retrieve an item from a DynamoDB table using Boto3 client vs resource?
AClient uses get_item with TableName parameter; resource uses Table object with get_item method without TableName.
BClient and resource do not support get_item method.
CBoth client and resource require TableName parameter in get_item method.
DClient uses Table object with get_item method; resource uses get_item with TableName parameter.
Attempts:
2 left
💡 Hint
Think about how client and resource interfaces differ in method calls.
query_result
intermediate
2:00remaining
Output of scan operation using client vs resource
Given the following code snippets, what is the type of the output returned by each scan operation? Client: ```python dynamodb_client = boto3.client('dynamodb') response = dynamodb_client.scan(TableName='MyTable') ``` Resource: ```python dynamodb_resource = boto3.resource('dynamodb') table = dynamodb_resource.Table('MyTable') response = table.scan() ```
AClient returns a dict with raw DynamoDB JSON; resource returns a dict with Python native types.
BClient returns a list of items; resource returns a dict with raw DynamoDB JSON.
CBoth client and resource return a list of items as Python dicts.
DClient returns a dict with Python native types; resource returns a list of items.
Attempts:
2 left
💡 Hint
Consider how Boto3 client and resource handle data types in responses.
📝 Syntax
advanced
2:00remaining
Correct syntax to update an item using resource
Which of the following code snippets correctly updates an attribute 'status' to 'active' for a given key in a DynamoDB table using Boto3 resource?
Atable.update_item(Key={'id': '123'}, UpdateExpression='SET status = active')
Btable.update_item(Key={'id': '123'}, UpdateExpression='SET status = :val', ExpressionAttributeValues={':val': {'S': 'active'}})
Ctable.update_item(Key={'id': '123'}, UpdateExpression='SET status = :val', ExpressionAttributeValues={':val': 'active'})
Dtable.update_item(Key={'id': '123'}, UpdateExpression='SET status = :val', ExpressionAttributeValues={':val': active})
Attempts:
2 left
💡 Hint
Remember how resource expects Python native types in ExpressionAttributeValues.
optimization
advanced
2:00remaining
Choosing client or resource for batch writes
You want to write 1000 items to a DynamoDB table efficiently. Which approach is better and why?
AUse resource's put_item method for each item because it is simpler.
BUse resource's batch_writer() because it automatically handles buffering and retries.
CUse client put_item in a loop because it gives more control over each write.
DUse client batch_write_item with single item per request for simplicity.
Attempts:
2 left
💡 Hint
Think about how batch_writer helps with large writes.
🔧 Debug
expert
2:00remaining
Why does this client code raise a ValidationException?
Consider this client code snippet: ```python response = dynamodb_client.get_item(Key={'id': '123'}, TableName='MyTable') ``` It raises a ValidationException with message: "One or more parameter values were invalid: Type mismatch for key id expected: S actual: N". What is the cause?
AThe key value '123' is passed as a plain string instead of DynamoDB JSON format with type.
BThe TableName parameter is missing from the get_item call.
CThe key attribute 'id' is missing from the Key dictionary.
DThe key value type does not match the table's key schema; it expects a string but got a number.
Attempts:
2 left
💡 Hint
Check the expected data type of the key attribute in the table schema.