0
0
AWScloud~10 mins

Lambda handler function structure in AWS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the AWS Lambda handler function name.

AWS
def [1](event, context):
    return 'Hello from Lambda!'
Drag options to blanks, or click blank then click option'
Ahandle_event
Blambda_handler
Cmain
Dprocess
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name not matching the handler setting.
Forgetting to define the handler function.
2fill in blank
medium

Complete the code to accept the event parameter in the Lambda handler function.

AWS
def lambda_handler([1], context):
    print(event)
    return 'Done'
Drag options to blanks, or click blank then click option'
Actx
Binput
Cevent
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names that do not match AWS Lambda expectations.
Swapping the order of parameters.
3fill in blank
hard

Fix the error in the Lambda handler function definition by completing the missing parameter.

AWS
def lambda_handler(event, [1]):
    print('Context:', context)
    return 'Success'
Drag options to blanks, or click blank then click option'
Acontext
Bdata
Cinfo
Dctx
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names for context.
Omitting the context parameter.
4fill in blank
hard

Fill both blanks to correctly return a JSON response with status code and body.

AWS
def lambda_handler(event, context):
    response = {
        'statusCode': [1],
        'body': [2]
    }
    return response
Drag options to blanks, or click blank then click option'
A200
B'{"message": "OK"}'
C404
D'Success'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numeric status code as string.
Returning body as a Python dict instead of JSON string.
5fill in blank
hard

Fill all three blanks to parse a key from the event and return it in the response body.

AWS
def lambda_handler(event, context):
    key_value = event.get([1], None)
    response = {
        'statusCode': [2],
        'body': f"Value is: { [3] }"
    }
    return response
Drag options to blanks, or click blank then click option'
A'key'
B200
Ckey_value
D'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong key string.
Not converting the value to string in the body.
Using incorrect status code.