Serverless-offline: POST request hanging

Created on 24 Dec 2020  路  8Comments  路  Source: dherault/serverless-offline

Bug Report

Current Behavior
Making POST requests to serverless-offline hangs forever but GET requests work as expected.

  • file: serverless.yml
service: test

frameworkVersion: '2'

provider:
  name: aws
  runtime: go1.x
  apiGateway:
    shouldStartNameWithService: true

package:
  individually: true
  exclude:
    - ./**

functions:
  hello:
    handler: bin/hello
    package:
      include:
        - ./bin/hello
    events:
      - http:
          path: hello
          method: ANY

plugins:
  - serverless-offline
  • file: hello/main.go
package main

import (
    "encoding/json"

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

// BodyRequest is our self-made struct to process JSON request from Client
type BodyRequest struct {
    RequestName string `json:"name"`
}

// BodyResponse is our self-made struct to build response for Client
type BodyResponse struct {
    ResponseName string `json:"name"`
}

// Handler function Using AWS Lambda Proxy Request
func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {

    // BodyRequest will be used to take the json response from client and build it
    bodyRequest := BodyRequest{
        RequestName: "",
    }

    // Unmarshal the json, return 404 if error
    err := json.Unmarshal([]byte(request.Body), &bodyRequest)
    if err != nil {
        return events.APIGatewayProxyResponse{Body: err.Error(), StatusCode: 404}, nil
    }

    // We will build the BodyResponse and send it back in json form
    bodyResponse := BodyResponse{
        ResponseName: bodyRequest.RequestName + " LastName",
    }

    // Marshal the response into json bytes, if error return 404
    response, err := json.Marshal(&bodyResponse)
    if err != nil {
        return events.APIGatewayProxyResponse{Body: err.Error(), StatusCode: 404}, nil
    }

    //Returning response with AWS Lambda Proxy Response
    return events.APIGatewayProxyResponse{Body: string(response), StatusCode: 200}, nil
}

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

Expected behavior/code
Should be able to POST. I have tried with other handlers other than Go and the result is the same.

Environment

  • serverless version: 2.16.1
  • serverless-offline version: 6.8.0
  • node.js version: v15.5.0
  • OS: macOS 10.15.7

  • go version: v1.15.6

Most helpful comment

It turns out node v15.5.0 was the issue. I downgraded to node v15.4.0 and it works as expected for POST.

All 8 comments

It turns out node v15.5.0 was the issue. I downgraded to node v15.4.0 and it works as expected for POST.

Thanks @JackFazackerley, you've saved me such a headache! Should this issue not remain open though? As it's quite a breaking bug, and a notice should at least be added to the readme file to spare anyone else having issues with this.

@ScottEnock I'm glad it helped! I guess it should actually, got ahead of myself at the time! Will reopen.

Encountered this after a fresh install on a new machine. Very frustrating. Thanks for this.

Only v15.5.x is not working. Please upgrade/downgrade Node version to solve this issue.

Running Node v.16.0.0 here, and I have this problem.

Running Node v.16.0.0 here, and I have this problem.

Works well on Node 15.14.0. Tested. Managing it via NVM

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranzSkuffka picture FranzSkuffka  路  3Comments

jormaechea picture jormaechea  路  4Comments

MEGApixel23 picture MEGApixel23  路  4Comments

dnalborczyk picture dnalborczyk  路  3Comments

Looveh picture Looveh  路  4Comments