1

I have a go script and I am making Terraform resource aws_lambda_function with runtime configurations as such :

  handler     = "main"
  memory_size = 512
  timeout     = 360
  runtime     = "go1.x"

In my go code, I have imported the modules :

"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/events"

and a snippet of code for ecr-sync.go

 func main() {
        lambda.Start(HandleRequest)
    }
    
    func HandleRequest(ctx context.Context, event event.HandleRequest)(string,error) {
      return string(body),err
}

The lambda function is deployed but while testing the function, it throws me following error:

{
  "errorMessage": "fork/exec /var/task/main: no such file or directory",
  "errorType": "PathError"
}

Anyone know how to fix this issue? I saw this post https://github.com/serverless/serverless/issues/4710 but I am not sure how I can set up the build confifguration through a pipeline as runtime configs are set up through terraform.

1 Answers1

1

"fork/exec /var/task/main: no such file or directory"

The error means that the executable in your lambda's zip file is not named main.

In the Go API for Lambda, the handler must be in the main package and it must be called in the main() function, just like yours. Neither package nor function name need to be set anywhere. The handler setting in the resource refers to the filename of the executable in the zip file uploaded.

From the error, it is clear that your zipfile does not have a main. (/var/task comes from the internal setup on the lambda side).

The lambda function is deployed but while testing the function, it throws me following error:

Yes, deploying a function does not verify that its handler configuration matches its zipfile. That error happens at runtime. Filename including extension is irrelevant, but must match the handler you specify in the lambda config.

To fix the error, check your zipfile, and update the handler to point to the executable. Keep in mind that Go lambdas must be compiled and the executable must be provided in the zipfile - unlike interpreted languages like Javascript of Python, source code does not go in the zipfile.

erik258
  • 14,701
  • 2
  • 25
  • 31
  • 1
    That's right, it worked. I changed the handler ="ecr-sync" and it found the file in my zip and it worked. I was not sure what are we giving in the handler as name as I didn't find a good doc regarding it. Thank you for your insight. It was helpful. – Urvashi Sharma Dec 02 '21 at 22:17