Bird
0
0

You want your AWS Lambda handler to process an event and return a JSON response with status code 200 and a message from the event. Which handler structure is correct?

hard📝 Application Q8 of 15
AWS - Lambda
You want your AWS Lambda handler to process an event and return a JSON response with status code 200 and a message from the event. Which handler structure is correct?
Adef lambda_handler(event): return {'statusCode': 200, 'body': event['message']}
Bdef lambda_handler(event, context): return {'statusCode': 200, 'body': event['message']}
Cdef lambda_handler(event, context): print(event['message']) return 200
Ddef lambda_handler(context, event): return {'statusCode': 200, 'body': event['message']}
Step-by-Step Solution
Solution:
  1. Step 1: Verify correct parameters and order

    The handler must accept event first, then context. def lambda_handler(event, context): return {'statusCode': 200, 'body': event['message']} follows this order.
  2. Step 2: Check return structure

    def lambda_handler(event, context): return {'statusCode': 200, 'body': event['message']} returns a dictionary with statusCode and body keys, which is the expected JSON response format.
  3. Final Answer:

    def lambda_handler(event, context): return {'statusCode': 200, 'body': event['message']} -> Option B
  4. Quick Check:

    Correct params and JSON response structure = def lambda_handler(event, context): return {'statusCode': 200, 'body': event['message']} [OK]
Quick Trick: Use (event, context) and return dict with statusCode and body [OK]
Common Mistakes:
  • Swapping event and context parameters
  • Omitting context parameter
  • Returning incorrect response format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes