I have uploaded an AWS Lambda function where the lambda_handler looks as follows:
import json
def lambda_handler(event, context):
print(event)
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!'),
'event': event
}
Problem 1: returning event
When I test it using the Lambda Management Console I can create a test event with parameters which also return the exact same format and all works fine:
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
However, when I use Postman, then I get something totally else, which returns to me:
{
"message": "Internal server error"
}
I suspect its because the event
looks something more like:
{'resource': '/hello', 'path': '/hello', 'httpMethod': 'GET', 'headers': {'Accept': '*/*', ... etc
Problem 2: adding json parameters in body creates an error
When I try in Postman to add in the body > raw > JSON(application/JSON) the keys above, then I get the error:
ERROR: The request could not be satisfied
Questions
I have two questions:
- How do I pass parameters in the body and be able to capture it in AWS lambda using the event or context?
- How do I return the event properly?
Content-Type:application/json
? – amanbPOST
request. If you are trying to do aGET
request, the body has no significance. This link maybe helpful docs.aws.amazon.com/apigateway/latest/developerguide/… – amanb