Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Created October 21, 2019 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcasalboni/2ca4767a70a557fae377544b6cd44369 to your computer and use it in GitHub Desktop.
Save alexcasalboni/2ca4767a70a557fae377544b6cd44369 to your computer and use it in GitHub Desktop.
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