Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS ALB - AWS Lambda handler (Python)
import json
def lambda_handler(event, context):
name = get_name(event) # extract inputs
message = get_message(name) # business logic
return build_response(message) # format output for ALB
def get_name(event):
# fetch inputs from event (could be missing)
return event['queryStringParameters'].get('name')
def get_message(name=None):
# my business logic
return "Hello %s!" % (name or 'world')
def build_response(message):
# build response for ALB
return {
"statusCode": 200,
"statusDescription": "200 OK",
"isBase64Encoded": False,
"headers": {
"Content-Type": "application/json",
},
"body": json.dumps({"message": message})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.