I'm writing a little POC and trying to work the best way to organize some lambdas. A service has 3 lambdas:
After deploying to AWS, when I test any of the lambdas, I get the following error:
{
"errorMessage": "fork/exec /var/task/cron: exec format error",
"errorType": "PathError"
}
In the logs, I find this:
START RequestId: 53a7feac-3a6d-4d18-8909-9c8bf659b727 Version: $LATEST
fork/exec /var/task/cron: exec format error: PathError
null
END RequestId: 53a7feac-3a6d-4d18-8909-9c8bf659b727
This is my project structure:
Each of these packages (except shared) is called main. See below:
Here's how I build the packages:
GOOS=linux
GOARCH=x86_64
echo "GOOS=$GOOS, GOARCH=$GOARCH"
go build -o out/main ./main.go
go build -o out/api ./api/index.go
go build -o out/messagehandler ./messagehandler/index.go
go build -o out/cron ./cron/index.go
The output is what I expected:
What I confirmed:
What is wrong here?
Is your OS Windows?
If so, it is suggested to use the following tool github.com/aws/aws-lambda-go/cmd/build-lambda-zip
to prepare the binary to deploy to AWS Lambda.
in cmd.exe:
set GOOS=linux
set GOARCH=amd64
set CGO_ENABLED=0
go build -o bootstrap main.go
%USERPROFILE%\Go\bin\build-lambda-zip.exe -o lambda-handler.zip bootstrap
or in Powershell
:
$env:GOOS = "linux"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "0"
go build -o bootstrap main.go
~\Go\Bin\build-lambda-zip.exe -o lambda-handler.zip bootstrap
More details here: https://github.com/aws/aws-lambda-go
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.