Bird
0
0

Given this Python Lambda handler:

medium📝 Predict Output Q4 of 15
AWS - Lambda
Given this Python Lambda handler:
def handler(event, context):
    print('Start')
    return event['key']

What happens if the event does not contain 'key'?
AThe function raises a KeyError and fails
BThe function returns None
CThe function returns an empty string
DThe function retries automatically
Step-by-Step Solution
Solution:
  1. Step 1: Analyze event dictionary access

    Accessing event['key'] when 'key' is missing raises a KeyError in Python.
  2. Step 2: Understand Lambda behavior on exceptions

    Lambda function fails and returns an error if an exception is raised and not handled.
  3. Final Answer:

    The function raises a KeyError and fails -> Option A
  4. Quick Check:

    Missing key in event = KeyError raised [OK]
Quick Trick: Access missing dict keys carefully to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Assuming missing keys return None
  • Expecting automatic retries on error
  • Thinking empty string is returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes