502 bad gateway error from cloudfront - internal server error

Hi, anyone has similiar issue ? I just deploy a simple service for a basic REST API, following a tutorial.

but when call it through CURL, it return error as below:

HTTP/1.1 502 Bad Gateway
Connection: keep-alive
Content-Length: 36
Content-Type: application/json
Date: Sat, 29 Jul 2017 17:24:45 GMT
Via: 1.1 73ca6a49ae80fd49bc58c66f9c46c2bf.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 5LHHMS0aOmcyEv78mJBF1J0gwC-u2zL5ltLmGBNwHyEr5yMdIr70Pw==
X-Cache: Error from cloudfront
x-amzn-RequestId: cf9d4393-7482-11e7-b27e-112c20856a3f

{
    "message": "Internal server error"
}

I have met similar issue for many times following different tutorial. the only change is runtime from node4.3 to node6.10 and region from us-east-1 to ap-northeast-2.

below the yml file and handler:

service: candidate-service

frameworkVersion: ">=1.1.0 <2.0.0"

provider:
  name: aws
  runtime: nodejs6.10
  stage: dev
  region: ap-northeast-1

functions:
  candidateSubmission:
    handler: api/candidate.submit
    memorySize: 128
    description: Submit candidate information and starts interview process.
    events:
      - http: 
          path: candidates
          method: post
'use strict';

module.exports.submit = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Go Serverless v1.0! Your function executed successfully!',
      input: event,
    }),
  };

  callback(null, response);

};

thanks.

Couple of things:

  1. Can you please show me your curl call?
  2. Can you run the code with sls invoke local --function ... and show the output?
  3. I see that you are specifying a memorySize: 128 to your function. Can you please remove that and see what happens?

Hi Rupak,

I solved this issue by downgrade to v1.17.0.

it’s due to the auto exclude devDependencies of v1.18.0.

now a new release v1.18.1 solved this issue.

thanks for your help.

Glad you got it working.

The 502 Bad Gateway error usually happens when there are some network errors between computer and internet severs . This means that a server (not necessarily a web server) acting as a gateway or proxy and received an invalid response from an upstream (or origin) server. In most cases the problem is not with you computer or your internet connection , it’s far more likely that it’s the website’s server instead. Often, simply refreshing or reloading the page (Ctrl-F5) will work, but sometimes the problem can persist for days.