Riddle me this!
Why lambda?
curl -X POST -H "Content-Type: application/json" -d '{"first_name":"ABCDE", "last_name": "john"}' https://8.execute-api.us-east-1.amazonaws.com/prod/HelloPython
{"message": "Internal server error"}
It works in the lambda test! Granted I am new but still How do I find out why? All I need in cloud metrics is a count of 500 errors. But I want to know why. I am doing a simple hello world.
import json
def respond(err, res=None):
return {
'statusCode': '400' if err else '200',
'body': err.message if err else json.dumps(res),
'headers': {
'Content-Type': 'application/json',
},
}
def my_handler(event, context):
message = 'Hello {} {}!'.format(event['first_name'],
event['last_name'])
res = {'message' : message }
return respond(None, res)
update - Below is the logs:
'first_name': KeyError
Traceback (most recent call last):
File "/var/task/hello_python.py", line 68, in my_handler
message = 'Hello
{}
{}
!'.format(event['first_name'],
KeyError: 'first_name'
I am confused. Is the events a what type of object? If a string do I need do use json.loads(event) to get a dict object?
first_nameis not being passed into the Lambda function. You should try logging the entireeventobject so you can see what is going on. Perhaps there is an issue with your API Gateway mapping template.