Reputation: 3433
I am new to server-less lambda function. I created one post request by using lambda. I deploy my app to AWS
. I am testing my app by using Postman. I tired my post request, I got internal server error.
. I also tested in api-gateway I got this errors:
Fri Mar 05 19:09:33 UTC 2021 : Endpoint response body before transformations: null
Fri Mar 05 19:09:33 UTC 2021 : Execution failed due to configuration error: Malformed Lambda proxy response
Fri Mar 05 19:09:33 UTC 2021 : Method completed with status: 502
I don't get what I did wrong. This is my yaml file post request event
createBeers:
handler: handlers/createBeers.createBeers
events:
- http:
path: createBeers
method: post
cors: true
This is my lambda function
'use strict';
const AWS = require('aws-sdk');
const dynamoDb = new AWS.DynamoDB.DocumentClient();
module.exports.createBeers = async event => {
const requestBody = JSON.parse(event.body);
const params = {
TableName: "tablename",
Item: {
beer_name: requestBody.beer_name,
beer_type: requestBody.beer_type,
beer_img_url: requestBody.beer_img_url,
beer_description: requestBody.beer_description,
alcohol_per: requestBody.alcohol_per
}
};
try {
await dynamoDb.put(params).promise();
return {
statusCode: 200,
body: JSON.stringify(requestBody),
};
} catch (error) {
console.log(error);
}
};
Upvotes: 1
Views: 1040
Reputation: 5747
Malformed Lambda proxy response
This sounds like your lambda is not returning the correct response. A few troubleshooting suggestions:
try {
await dynamoDb.put(params).promise();
return {
statusCode: 200,
body: JSON.stringify(requestBody),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify(error),
};
}
Upvotes: 1