5

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.

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
user504909
  • 9,119
  • 12
  • 60
  • 109
  • 3
    Can you give us the logs from your service with `serverless logs -f yourfunction -s dev` ? (Obviously, replace `yourfunction` with "first" or "second" as defined in your serverless.yml) – Quentin Hayot Sep 20 '18 at 12:40
  • How do you deploy? Was the deployment successful? Once you deploy you should see the URLs of you deployed functions. Do you get that 502 during deployment or once you try to use your deployed functions? – iaforek Sep 20 '18 at 12:45
  • BTW you should use: `export const hello = async (event, context, callback) => {` and then instead of `return rep` use `return callback(null, rep)` - I'd say this is why you are getting the error. – iaforek Sep 20 '18 at 12:46
  • @ iaforek can you help me answer my another question? https://stackoverflow.com/questions/52425229/javascript-serverless-error-of-json-object-return – user504909 Sep 20 '18 at 12:49
  • @user504909 Did that work? – iaforek Sep 20 '18 at 14:00

0 Answers0