Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exec format error when running AWS Golang Lambda

I have a go application, structured like this:

cmd
|
reports
|
main.go

main.go imports internal/reports package and has a single function, main(), which delegates call to aws-lambda-go/lambda.Start() function.

Code is build running the commands (snippet):

cd internal/reports && go build handler.go
cd ../..
go build -o reports ../cmd/reports/main.go && chmod +x reports && zip reports.zip reports

reports.zip is uploaded to AWS Lambda, which in turns throws an error when Test button is pressed:

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

reports is set as Lambda's Handler.

Also, code is build on Ubuntu 14.04 machine, as a part of aws/codebuild/ubuntu-base:14.04 Docker Image, on AWS CodeBuild. There should be no environment issues here, even though the error suggests a cross-platform problem.

Any ideas?

like image 988
Ivan Avatar asked Jun 05 '18 13:06

Ivan


2 Answers

You have to build with GOARCH=amd64 GOOS=linux. Wherever you build your binary, the binary for Lambda is run on Amazon Linux.

So , try this build command.

GOARCH=amd64 GOOS=linux go build handler.go

like image 128
Toshinori Sugita Avatar answered Oct 31 '22 13:10

Toshinori Sugita


The issue is that main() function is not declared in main package, which is mandatory by Golang language spec

like image 29
Ivan Avatar answered Oct 31 '22 13:10

Ivan