I have followed this tutorial: https://www.serverless.com/blog/node-rest-api-with-serverless-lambda-and-dynamodb. It guides you on building a Lambda function that takes three parameters and populates a DynamoDB database with an Item built from these parameters.
Everything works as expected when I run things from my console using CURL. However, if I test things via the Lambda Console I get an error, and it seems to be due to the 'event' object in my handler's parameters being shaped differently depending on where I call the Lambda function from (which is weird).
I tested the following:
module.exports.submit = async (event, context) => {
return {
statusCode: 200,
body: Object.keys(event).join()
}
}
And using CURL with the following statement I get(personal details are from the Tutorial):
curl -H "Content-Type: application/json" -X POST -d '{"fullname":"Shekhar Gulati","email": "[email protected]", "experience":12}' https://__.execute-api.eu-west-2.amazonaws.com/dev/__
The response from this CURL statement is quite long
resource,path,httpMethod,headers,multiValueHeaders,queryStringParameters,multiValueQueryStringParameters,pathParameters,stageVariables,requestContext,body,isBase64Encoded
On the other hand, in the console, the response is simply:
firstname,email,experience
Should I just ignore the console for testing purposes or am I missing something?
curlit's going through API Gateway which is adding lots of things to theeventobject. When you test directly in the Lambda console you probably aren't passing all those API Gateway values in the test event object you created, thus the difference. - Mark B