Created
October 21, 2019 13:47
-
-
Save alexcasalboni/2ca4767a70a557fae377544b6cd44369 to your computer and use it in GitHub Desktop.
AWS ALB - AWS Lambda handler (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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