dherault / dherault/serverless-offline

Cannot launch go lambda

Open
#1,644 3 comments 5 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## 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**

```go
#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

```yaml
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**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.