4

When deploying this Go-based AWS Lambda project, via AWS console, I receive:

{
  "errorMessage": "fork/exec /var/task/main: exec format error",
  "errorType": "PathError"
}

Here are the steps I took:

  • downloaded the marriage-master project from Git
  • in Terminal, go get "github.com/aws/aws-lambda-go/lambda" so the script is buildable by Go
  • in Terminal, go build main.go to create file Lambda will use to execute
  • in Terminal, zip main.zip main to archive the file into a .zip for deployment to Lambda
  • in AWS Console, upload main.zip to Function code

enter image description here

  • in AWS Console, changed Handler to main.

enter image description here

But I keep getting this path error. Any idea what I'm doing wrong?

user53526356
  • 934
  • 1
  • 11
  • 25

4 Answers4

12

To deploy a Go app in AWS Lambda, run the following commands:

  1. Build the binary targeted to Linux OS and amd64 architecture

    GOARCH=amd64 GOOS=linux go build main.go -ldflags="-s -w"

  2. Zip the binary

    zip lambda.zip main

  3. Upload this binary from AWS Lambda console directly or Put it in an S3 bucket and import it.

You have taken care of the lambda configuration already.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mayank Patel
  • 8,088
  • 5
  • 55
  • 75
7

Try without flags:

GOARCH=amd64 GOOS=linux go build main.go
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
3

Do this GOARCH=amd64 GOOS=linux go build main.go worked for me.

Titanium
  • 31
  • 3
2

My issue was the package name wasn't named main

https://stackoverflow.com/a/50701572/2639163

Zzeks
  • 571
  • 2
  • 5
  • 9