Your handler is incorrect and you are missing runtime. I would also recommend using standard main.js
in the form of:
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify("Hi from lambda on localstack")
}
};
Then, your aws_lambda_function
with correct handler
and runtime
should be:
resource "aws_lambda_function" "lambda" {
filename = "lambda_file.zip"
function_name = "handler"
runtime = "nodejs12.x"
role = aws_iam_role.iam_for_lambda.arn
handler = "main.handler"
source_code_hash = filebase64sha256(data.archive_file.lambda_file.output_path)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…