I got a lambda written in Go running on a container, the image was built with alpine-golang and run with alpine.
When testing i noticed from the logs the lambda is ran twice before exiting with the following:
Error: Runtime exited without providing a reason Runtime.ExitError
From my local system this the code runs fine without errors, i earlier tried running without a container but still faced runtime issues. The only error handling and logging mechs in my code is log.Println
and fmt.Printf
. Anyone got an idea of what is going on?
EDIT:
I trapped the exit code, which is turns out to be 0
but lambda exits with
Runtime exited with error: exit status 1 Runtime.ExitError
2
Answers
Make sure you are following the recommended guide lines aws provide with building the container image. https://docs.aws.amazon.com/lambda/latest/dg/go-image.html
your Dockerfile should look like this to work with lambda,
Lambda is very strange where if you have the Dockerfile like you would on a local machine then it runs it once, ends, then a second time and crashes with no reason given
I really suggest going for the "without container" path. Just pack your executable into a .zip archive. Don’t forget to compile with
GOOS=linux
for your code to be compatible with AWS Lambda.On Linux you can use the following commands to get your archive:
Note that you have to set
Handler
to beexecutableName
in function’s Runtime settings.For handling lambda function, you have to use
github.com/aws/aws-lambda-go/lambda
package and in main start the handler function likelambda.Start(handler)
.Full code example: