Bird
0
0

What is wrong with this AWS Lambda handler function?

medium📝 Debug Q7 of 15
AWS - Lambda
What is wrong with this AWS Lambda handler function?
def lambda_handler(event, context):
    print(event['data'])
    return
AThe function returns None implicitly, which may cause issues if a response is expected.
BThe print statement is invalid in Lambda functions.
CThe event parameter should not be accessed directly.
DThe context parameter is unused and must be removed.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the return statement

    The function returns nothing explicitly, so Python returns None by default.
  2. Step 2: Consider Lambda response expectations

    If the Lambda is invoked synchronously and expects a response, returning None may cause unexpected behavior or errors.
  3. Final Answer:

    The function returns None implicitly, which may cause issues if a response is expected. -> Option A
  4. Quick Check:

    Lambda should return a value if response expected [OK]
Quick Trick: Always return a value if Lambda expects a response [OK]
Common Mistakes:
  • Assuming print is disallowed
  • Ignoring return value importance
  • Removing unused context parameter incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes