Search code examples
aws-lambdaterraformamazon-sqs

Lambda can't find the file test_lambda.js. Make sure that your handler upholds the format: file-name.method


I am facing an issue with my AWS Lambda trigger function where the console appears to say Lambda can't find the file test_lambda.js. Make sure that your handler upholds the format: file-name.method.

Here is my relevant code. Here is the lambda function itself -

resource "aws_lambda_function" "development_lambda" {
  function_name = "test_lambda"
  role          = "${aws_iam_role.iam_for_lambda.arn}"
  handler       = "test_lambda"
  runtime = "nodejs10.x"

  filename      = "test_lambda.js.zip"
  source_code_hash = "${filebase64sha256("test_lambda.js.zip")}"

  timeout = 10

  vpc_config {
    subnet_ids         = flatten(["${private_subnet_ids}"])
    security_group_ids = flatten(["${security_group_id}"])
  }

  environment {
    variables = {
      env = "localhost"
    }
  }
}

Here is the event source mapping code -

resource "aws_lambda_event_source_mapping" "event_source_mapping" {
  event_source_arn = "${aws_sqs_queue.development-queue.arn}"
  enabled          = true
  function_name    = "${aws_lambda_function.development_lambda.arn}"
  batch_size       = 10
}

And here is the lambda handler in file test_lambda.js

exports.handler = (event, context, callback) => {
    console.log("Lambda test");
    callback(null, 'In Lambda');
};

I also have a test_lambda.js.zip in the same path.

What is wrong here ?


Solution

  • Your handler should be test_lambda.handler.