I am new in AWS trying to learn, how to make a REST API(Non-Proxy Integration) with Lambda function and Dynamo DB. I have enabled the cors, configured the Method Request and Method Response of REST API in resources. My Lambda function code seems to be correct, but when I call this API from POSTMAN or react application it returns NULL.
LAMBDA FUNCTION:-
var AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient({region : 'us-west-2'});
exports.handler = async (event) => {
if(event.httpMethod==='GET')
{
console.log("GET method if is called")
return readDatabase(event);
}
};
function readDatabase(event)
{
try{
console.log("inside readDatabase function")
let params = {
TableName: 'devicedata',
};
return ddb.scan(params).promise()
.then(data=>{
const response ={
statusCode: 200,
body : JSON.stringify({
"deviceData" : data
})
}
return response;
});
}
catch (e) {
let response = {
statusCode: 400,
body: JSON.stringify({
"Message": "Error in Read From Database function",
"Details": e
})
}
return response;
}
}
REST API RESOURCES:-
Integration Response Header Mapping :-

Method Reponse Configuration:-

These are the configurations, but it sends output as - "null".




