Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
DynamoDB - with AWS SDK
What is wrong with this code snippet?
import boto3
resource = boto3.resource('dynamodb')
response = resource.get_item(TableName='MyTable', Key={'id': '123'})
print(response['Item'])
Aresource object does not have get_item method; use Table object instead.
BKey dictionary is missing attribute type specification.
CTableName parameter should be lowercase 'tablename'.
Dprint statement should be print(response['Items']).
Step-by-Step Solution
Solution:
  1. Step 1: Check resource method availability

    The resource object itself does not have get_item; this method belongs to Table resource objects.
  2. Step 2: Correct usage

    You must get a Table object first, e.g., resource.Table('MyTable').get_item(...).
  3. Final Answer:

    resource object does not have get_item method; use Table object instead. -> Option A
  4. Quick Check:

    Use resource.Table('name') to call get_item [OK]
Quick Trick: Call get_item on Table resource, not on resource itself [OK]
Common Mistakes:
MISTAKES
  • Calling get_item directly on resource
  • Ignoring need for Table object
  • Misusing Key parameter format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes