Bird
0
0

Analyze this AWS Lambda Python function:

medium📝 Debug Q6 of 15
AWS - Lambda
Analyze this AWS Lambda Python function:
def lambda_handler(event, context):
    return event['data']

If the event does not contain the 'data' key, what will happen?
AThe function returns 'data' as a string
BThe function returns None
CThe function returns an empty string
DThe function raises a KeyError exception
Step-by-Step Solution
Solution:
  1. Step 1: Accessing dictionary key directly

    Using event['data'] raises KeyError if 'data' key is missing.
  2. Step 2: No exception handling present

    Since no try-except or get() method is used, exception occurs.
  3. Final Answer:

    The function raises a KeyError exception -> Option D
  4. Quick Check:

    Direct dict access fails if key missing [OK]
Quick Trick: Direct dict access fails if key missing [OK]
Common Mistakes:
MISTAKES
  • Assuming get() method is used
  • Expecting None instead of exception
  • Ignoring exception possibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes