Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"no such file or directory" when executing Go function in AWS Lambda #4710

Closed
Napas opened this issue Feb 2, 2018 · 12 comments
Closed

"no such file or directory" when executing Go function in AWS Lambda #4710

Napas opened this issue Feb 2, 2018 · 12 comments

Comments

@Napas
Copy link

Napas commented Feb 2, 2018

When running my Lambda function I get this error:

START RequestId: 3df5e64a-0863-11e8-903f-919b29535603 Version: $LATEST fork/exec /var/task/bin/ping: no such file or directory: PathError null END RequestId: 3df5e64a-0863-11e8-903f-919b29535603 REPORT RequestId: 3df5e64a-0863-11e8-903f-919b29535603 Duration: 0.21 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 12 MB

I did check zip file in S3 - it has an executable in it ./bin/ping

Any ideas how to solve that?

My serverless.yml

service: ping
provider:
  name: aws
  runtime: go1.x
  stage: staging
  region: us-east-1
  memorySize: 128
  timeout: 1

package:
 exclude:
   - ./**
 include:
   - ./bin/**

functions:
  ping:
    handler: bin/ping
    events:
      - http:
          path: ping
          method: get
          private: false

my ping/main.go file:

package main

import (
	"github.com/aws/aws-lambda-go/lambda"
	"time"
	"github.com/aws/aws-lambda-go/events"
	"encoding/json"
)

// Response object
type Response struct {
	Payload string            `json:"Payload"`
	Meta    map[string]string `json:"Meta"`
}

// Ping handles ping response
func Ping(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
	meta := make(map[string]string)
	meta["CreatedAt"] = time.Now().Format(time.RFC3339);
	resp := Response{
		Payload: "Pong",
		Meta: meta,
	}

	body, _ := json.Marshal(resp)

	return events.APIGatewayProxyResponse{
		StatusCode: 200,
		Body: string(body),
	}, nil
}

func main() {
	lambda.Start(Ping)
}
@Napas
Copy link
Author

Napas commented Feb 3, 2018

Ok, found a solution. If someone else will have this issue: somehow Golang Alpine images doesn't build statically linked binary:
ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, stripped

The interpreter doesn't exist in Lambda environment so that's why it throws "no such file or directory error".

To solve that modify your Makefile to use
env GOOS=linux go build -v -ldflags '-d -s -w' -a -tags netgo -installsuffix netgo -o bin/service service/main.go as a build command.

@Napas Napas closed this as completed Feb 3, 2018
@jdchmiel
Copy link

It also does not like C header includes, where the non alpine image works just fine.

@gadelkareem
Copy link

gadelkareem commented May 25, 2020

this worked for me

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-s -w' -a -installsuffix cgo -o -o bin/service service/main.go

@rajendragosavi
Copy link

@gadelkareem , where did you add this ? I am using helloworld example of AWS SAM.

@gadelkareem
Copy link

@rajendragosavi it for the Alpine image that is building the go binary in your pipeline

@rajendragosavi
Copy link

@gadelkareem , I am just following AWS SAM hello-world example. and I am getting some error .
I am invoking - sam local invoke HelloWorldFunction --no-event
"errorType":"exitError","errorMessage":"RequestId: 1bd9d3cd-442a-1519-3878-8ebe490a5e95 Error: fork/exec /var/task/hello-world: permission denied"

@rajendragosavi
Copy link

@Napas - How did you resolve this issue? I am following AWS SAM hello-world example and I getting error- "errorType":"exitError","errorMessage":"RequestId: 1bd9d3cd-442a-1519-3878-8ebe490a5e95 Error: fork/exec /var/task/hello-world: permission denied"

@dheerajappin
Copy link

i am using lambda promtail function with go latest version but getting the following error:
fork/exec /var/task/handler: no such file or directory: PathError null

@amadejkastelic
Copy link

i am using lambda promtail function with go latest version but getting the following error: fork/exec /var/task/handler: no such file or directory: PathError null

Same issue, did you manage to fix it?

@dheerajappin
Copy link

dheerajappin commented Jan 4, 2022 via email

@vikhyat187
Copy link

is this fixed? Even I'm facing the same error.

@bernardgardner
Copy link

So another cause of this is failing to build the go binaries before using serverless to deploy the lambdas - at least in our case, sls would happily deploy lambdas with the supporting files in the zip, but not including the executable, so the "no such file or directory" error was quite literal - the file wasn't there...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants