I am trying to debug lambda function locally using SAM cli and AWS CDK. So I am getting error function module not found any idea why so? I have taken this project from github https://github.com/mavi888/cdk-serverless-get-started
function.js:
exports.handler = async function (event) {
console.log("request:", JSON.stringify(event));
// return response back to upstream caller
return sendRes(200, "HELLLOOO");
};
const sendRes = (status, body) => {
var response = {
statusCode: status,
headers: {
"Content-Type": "text/html",
},
body: body,
};
return response;
};
Inside lib folder
// lambda function
const dynamoLambda = new lambda.Function(this, "DynamoLambdaHandler", {
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.asset("functions"),
handler: "function.handler",
environment: {
HELLO_TABLE_NAME: table.tableName,
},
});
I am using cdk synth > template.yaml
command which generates cloud formation template.yaml file. Now I find function name with logicalID eg: myFunction12345678 and then trying to debug it locally using this command sam local invoke myFunction12345678
in my case it is DynamoLambdaHandler function. I get function module not found error. Any idea what I am missing?
Code is available on github: https://github.com/mavi888/cdk-serverless-get-started