serverless on aws lambda got 502 error of Internal server error

时间:2018-09-19 08:23:43

标签: node.js aws-lambda serverless bad-gateway

I try to use serverless with aws lambda service.

my serverless.yml is:

service: webpack-4-example

# Add the serverless-webpack plugin
plugins:
  - serverless-webpack
  - serverless-offline

provider:
  name: aws
  runtime: nodejs8.10
  region: us-west-2
  stage: dev

package:
  individually: true

functions:
  first:
    handler: handlers/first.hello
    events:
      - http:
          method: get
          path: /first
  second:
    handler: handlers/second.hello
    events:
      - http:
          method: get
          path: /second

custom:
  webpack:
    webpackConfig: 'webpack.config.js'
    includModules: true
    packager: 'npm'

I use serverless-webpack and serverless-offline plugins.

I just write simple serverless for first.js

export const hello = async (event, context) => {
const rep = {
statusCode: 200,
body: JSON.stringify({
  message: 'v1.0',
  input: event,
})
};
return rep;
};

it can run correctly in localmachine by command line:

sls offline start

and give me correct json response.

but it give me error when I try to deploy on aws cloud:

it give me 502 gateway error, with response body:

{"message": "Internal server error"}

How to debug on aws serverless cloud and how to fix this error.

0 个答案:

没有答案