Lambda Hello World (Python)
Create the function
- Lambda console -> Create function -> Author from scratch.
- Name:
hello-python, Runtime: Python 3.12.
- Handler:
import json
def lambda_handler(event, context):
name = (
(event.get("queryStringParameters") or {}).get("name")
or event.get("name")
or "world"
)
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps({"message": f"Hello, {name}"})
}
- Save, create a test event (e.g.,
{"name":"Bob"}), and view CloudWatch logs.
- Optional: add a 400 response for missing/invalid input.