Lambda Hello World (Python)

Create the function

  1. Lambda console -> Create function -> Author from scratch.
  2. Name: hello-python, Runtime: Python 3.12.
  3. 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}"})
    }
  1. Save, create a test event (e.g., {"name":"Bob"}), and view CloudWatch logs.
  2. Optional: add a 400 response for missing/invalid input.