dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.21k stars 795 forks source link

Cannot launch go lambda #1644

Open exasky opened 1 year ago

exasky commented 1 year ago

Bug Report

Current Behavior

I can't manage to make serverless-offline work with golang environment.

When I do the http call: GET http://localhost:3000/ping, I have the error

× Unhandled exception in handler 'package-validation'.
× { Error: Command failed with exit code 1: ./tmp
'tmp' is not recognized as an internal or external command

Aside from this, I can't pass an executable to the 'handler' part of the serverless.ym. If I do : handler: bin/main.exe, I have this error:

× Unhandled exception in handler 'package-validation'.
× { [Error: ENOENT: no such file or directory, open 'C:\{path_to_project}\lambda\bin\main.go']

If I do: handler: bin/main, I have this error:

× Unhandled exception in handler 'package-validation'.
× { [Error: ENOENT: no such file or directory, open 'C:\{path_to_project}\lambda\.go']

Sample Code

#main.go
package main

import (
    "context"
    "log"

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

func handleRequest(ctx context.Context,) (string, error) {
    return "", nil
}

func main() {
    lambda.Start(handleRequest)
}
service: myservice
frameworkVersion: "3"

plugins:
  - serverless-offline

provider:
  name: aws
  runtime: go1.x

functions:
  hello:
    #handler: bin/hello
    handler: hello/main.go
    events:
      - http:
          path: /ping
          method: get

Expected behavior/code

Go file should be executed correctly on http call

Environment

optional, if you are using any of the following frameworks to invoke handlers

Possible Solution

I ran into GoRunner.js, adding some console.log, what I see is : most of the time , main.go file is deleted from tmp directory during the go build command.

Additional context/Screenshots

s850042002 commented 1 year ago

useDocker option solves the issue in my environment.

adherb commented 1 year ago

Are there any updates on this?

rafaelnunez commented 11 months ago

I had the same issue. I fixed it so :point_down: