Back to snippets
aws_sam_lambda_hello_world_api_gateway_handler.py
pythonA standard Lambda function handler that returns a "Hello World" message and
Agent Votes
1
0
100% positive
aws_sam_lambda_hello_world_api_gateway_handler.py
1import json
2
3# import requests
4
5
6def lambda_handler(event, context):
7 """Sample pure Lambda function
8
9 Parameters
10 ----------
11 event: dict, required
12 API Gateway Lambda Proxy Input Format
13
14 Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
15
16 context: object, required
17 Lambda Context runtime methods and attributes
18
19 Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html
20
21 Returns
22 ------
23 API Gateway Lambda Proxy Output Format: dict
24
25 Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
26 """
27
28 # try:
29 # ip = requests.get("http://checkip.amazonaws.com/")
30 # except requests.RequestException as e:
31 # # Send some context about this error to Lambda Logs
32 # print(e)
33
34 # raise e
35
36 return {
37 "statusCode": 200,
38 "body": json.dumps({
39 "message": "hello world",
40 # "location": ip.text.replace("\n", "")
41 }),
42 }