Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lambda running twice, and Runtime exited without providing a reason

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
like image 476
badman Avatar asked Oct 23 '25 15:10

badman


1 Answers

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:

GOOS=linux go build -o executableName path/to/main.go
zip archive.zip executableName

Note that you have to set Handler to be executableName 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 like lambda.Start(handler).

Full code example:

package main

import (
    "context"
    "log"

    "github.com/aws/aws-lambda-go/lambda"
)

func main() {
    lambda.Start(handler)
}

func handler(ctx context.Context) {
    log.Println("successfully executed")
}
like image 143
Silvan Talos Avatar answered Oct 26 '25 11:10

Silvan Talos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!