Bird
0
0

Given this Python code snippet for DynamoDB, what will be the output if a throttling error occurs on the first attempt?

medium📝 query result Q13 of 15
DynamoDB - with AWS SDK
Given this Python code snippet for DynamoDB, what will be the output if a throttling error occurs on the first attempt?
import boto3
from botocore.exceptions import ClientError

client = boto3.client('dynamodb')

try:
    response = client.put_item(TableName='MyTable', Item={'id': {'S': '123'}})
    print('Success')
except ClientError as e:
    if e.response['Error']['Code'] == 'ThrottlingException':
        print('Retrying...')
    else:
        print('Failed')
ASuccess
BRetrying...
CFailed
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the try-except block behavior

    If a ClientError occurs, the code checks the error code inside the except block.
  2. Step 2: Check error code for throttling

    If the error code is 'ThrottlingException', it prints 'Retrying...'. Otherwise, it prints 'Failed'.
  3. Final Answer:

    Retrying... -> Option B
  4. Quick Check:

    Error code 'ThrottlingException' triggers 'Retrying...' [OK]
Quick Trick: Check error code in except to decide output [OK]
Common Mistakes:
MISTAKES
  • Assuming success despite error
  • Ignoring error code check and printing 'Failed'
  • Expecting no output on error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes