lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

Help runing a go lambda function locally #340

Closed pinzon closed 3 years ago

pinzon commented 3 years ago

So I'm trying to run a go lambda function locally as a test. Base on the go1.x run image Dockerfile I made this process:

  1. Download the function runtime from https://lambci.s3.amazonaws.com/fs/go1.x.tgz and unzip it
  2. Compile my function (function.go
    
    package main

import ( "context" "fmt" "os"

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

)

type MyEvent struct { Name string json:"name" }

func HandleRequest(ctx context.Context, name MyEvent) (string, error) { fmt.Println(os.Getenv("_LAMBDA_LOG_FD")) return fmt.Sprintf("Hello %s!", name.Name), nil }

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


3. Trying to run the function with aws-lambda-go
`AWS_EXECUTION_ENV=AWS_Lambda_go1.x _LAMBDA_LOG_FD=9  GOPROXY=direct  ./var/runtime/aws-lambda-go --debug ./function  '{"name":"kevs"}'`

But I'm getting this logs, and I'm not sure what to do next.

02 Jul 2021 02:14:34,916 [ERROR] (runtime_init_optional_cleanup@src/lambda/runtime.c:900 errno: Bad file descriptor) (lambda_set_log_fd(fd)) == 0 failed. 02 Jul 2021 02:14:34,916 [ERROR] (runtime_init_optional_cleanup@src/lambda/runtime.c:968 errno: Bad file descriptor) Runtime internal error 2021/07/01 21:14:34 runtime_init failed



Thank you in advance for your help.
pinzon commented 3 years ago

Found out how to do it.

edwardofclt commented 3 years ago

@pinzon this is when you share your discovery just in case.

pinzon commented 3 years ago

jajaja sorry, you're right. I wrote this code with what I found inside the code of this project. The makefile explains how to use it.