Getting error "fork/exec /var/task/main: no such file or directory" while executing aws-lambda function

Pooja K Bhatt picture Pooja K Bhatt · Sep 27, 2019 · Viewed 8k times · Source

Getting error fork/exec /var/task/main: no such file or directory while executing lambda function.

I am using windows platform to run and build code in Go.

I have done following steps to deploy go aws-lambda handler:

  1. Written code in go language with VSCode in windows platform
  2. Build project with : go build main.go
  3. Convert main.exe to main.zip
  4. Uploaded main.zip with handler name main aws-lambda fuction using aws console account
  5. Created test event to test lambda function
  6. Got error "fork/exec /var/task/main: no such file or directory while executing lambda function"
package main

import (
    "fmt"

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

// Request represents the requested object
type Request struct {
    ID    int    `json:"ID"`
    Value string `json:"Value"`
}

// Response represents the Response object
type Response struct {
    Message string `json:"Message"`
    Ok      bool   `json:"Ok"`
}

// Handler represents the Handler of lambda
func Handler(request Request) (Response, error) {
    return Response{
        Message: fmt.Sprint("Process Request Id %f", request.ID),
        Ok:      true,
    }, nil
}

func main() {
    lambda.Start(Handler)
}

build command

go build main.go

Detail Error in AWS console

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

Log Output in AWS console

START RequestId: 9ef206ed-5538-407a-acf0-06673bacf2d7 Version: $LATEST
fork/exec /var/task/main: no such file or directory: PathError
null
END RequestId: 9ef206ed-5538-407a-acf0-06673bacf2d7
REPORT RequestId: 9ef206ed-5538-407a-acf0-06673bacf2d7  Duration: 0.64 ms   Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 31 MB  Init Duration: 1.49 ms

Answer

mch.zawalski picture mch.zawalski · Jul 8, 2020

In my case the problem was default setted handler to 'hello' function.

Needed to change it to 'main' via AWS Lambda view panel -> Basic Settings -> Edit.

AWS Lambda function