'"PathError" when deploying Go project to AWS Lambda
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
toFunction code
- in AWS Console, changed
Handler
tomain
.
But I keep getting this path error. Any idea what I'm doing wrong?
Solution 1:[1]
To deploy a Go app in AWS Lambda, run the following commands:
Build the binary targeted to Linux OS and amd64 architecture
GOARCH=amd64 GOOS=linux go build main.go -ldflags="-s -w"
Zip the binary
zip lambda.zip main
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.
Solution 2:[2]
Try without flags:
GOARCH=amd64 GOOS=linux go build main.go
Solution 3:[3]
Do this GOARCH=amd64 GOOS=linux go build main.go
worked for me.
Solution 4:[4]
My issue was the package name wasn't named main
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dharman |
Solution 2 | Tomerikoo |
Solution 3 | Titanium |
Solution 4 | Zzeks |