Complete the code to define a basic AWS Lambda function handler in Python.
def lambda_handler(event, context): return [1]
The Lambda handler must return a value, here a simple greeting string.
Complete the code to access the 'name' key from the event dictionary in the Lambda function.
def lambda_handler(event, context): name = event[1]"name" return f"Hello, {name}!"
Event is a dictionary; use square brackets to access keys.
Fix the error in the Lambda function code to correctly handle missing 'age' key in event.
def lambda_handler(event, context): age = event.get([1], 0) return f"Age is {age}"
The key must be a string in quotes when using dict.get().
Fill both blanks to create a Lambda function that returns the square of a number passed in event.
def lambda_handler(event, context): number = event[1]"number" result = number [2] 2 return result
Access the number with event["number"] and use ** for exponentiation.
Fill all three blanks to create a Lambda function that returns a dictionary with the original number, its square, and a greeting message.
def lambda_handler(event, context): num = event[1]"num" square = num [2] 2 return [3]
Access 'num' with event["num"], square with **, and return a dictionary with keys and values.