serverless-offline icon indicating copy to clipboard operation
serverless-offline copied to clipboard

Cannot launch go lambda

Open exasky opened this issue 2 years ago • 3 comments

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)
}

  • file: serverless.yml
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

  • serverless version: 3.26.0
  • serverless-offline version: 12.0.4
  • node.js version: v16.17.1
  • OS: Windows 10

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

  • go version: 1.19.3

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

exasky avatar Jan 09 '23 11:01 exasky

useDocker option solves the issue in my environment.

s850042002 avatar May 20 '23 06:05 s850042002

Are there any updates on this?

adherb avatar Aug 26 '23 05:08 adherb

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

rafaelnunez avatar Dec 15 '23 21:12 rafaelnunez