0
0
AWScloud~10 mins

Lambda function concept 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 a basic AWS Lambda function handler in Python.

AWS
def lambda_handler(event, context):
    return [1]
Drag options to blanks, or click blank then click option'
Aprint("Hello")
B"Hello from Lambda!"
Cevent + context
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of return
Returning None which means no response
2fill in blank
medium

Complete the code to access the 'name' key from the event dictionary in the Lambda function.

AWS
def lambda_handler(event, context):
    name = event[1]"name"
    return f"Hello, {name}!"
Drag options to blanks, or click blank then click option'
A["name"]
B("name")
C.name
D{'name'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or dot notation which are invalid for dict access
3fill in blank
hard

Fix the error in the Lambda function code to correctly handle missing 'age' key in event.

AWS
def lambda_handler(event, context):
    age = event.get([1], 0)
    return f"Age is {age}"
Drag options to blanks, or click blank then click option'
Aage
Bevent
C0
D"age"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name without quotes
Passing wrong type as key
4fill in blank
hard

Fill both blanks to create a Lambda function that returns the square of a number passed in event.

AWS
def lambda_handler(event, context):
    number = event[1]"number"
    result = number [2] 2
    return result
Drag options to blanks, or click blank then click option'
A["number"]
B**
C*
D("number")
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of ** for square
Using parentheses instead of brackets for dict access
5fill in blank
hard

Fill all three blanks to create a Lambda function that returns a dictionary with the original number, its square, and a greeting message.

AWS
def lambda_handler(event, context):
    num = event[1]"num"
    square = num [2] 2
    return [3]
Drag options to blanks, or click blank then click option'
A["num"]
B**
C{"number": num, "square": square, "message": "Hello!"}
D("num")
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of brackets
Using * instead of **
Returning a string instead of a dictionary