繁体   English   中英

无服务器 502 错误网关

[英]Serverless 502 Bad Gateway

我可以按照文档创建一个简单的无服务器函数,但是当我添加http侦听器时,我在尝试访问我的端点时不断收到502 Bad Gateway

我该如何调试?

'use strict';

module.exports.hello = async (event, context) => {
  return {
    statusCode: 200,
    body: {
      message: 'Go Serverless v1.0! Your function executed successfully!',
      input: event,
    },
  };
};

无服务器.yaml

service: playing-with-serverless # NOTE: update this with your service name

provider:
  name: aws
  runtime: nodejs8.10

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get

我已经部署了我的功能

 $ sls deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (423 B)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...
Service Information
service: playing-with-serverless
stage: dev
region: us-east-1
stack: playing-with-serverless-dev
api keys:
  None
endpoints:
  GET - https://1r5mt9wa63.execute-api.us-east-1.amazonaws.com/dev/hello
functions:
  hello: playing-with-serverless-dev-hello
layers:
  None
Serverless: Removing old service artifacts from S3...

卷曲

$ curl --request GET \
  --url https://1r5mt9wa63.execute-api.us-east-1.amazonaws.com/dev/hello
{"message": "Internal server error"}%```  

您需要在响应对象中对body进行字符串化:

return {
  statusCode: 200,
  body: JSON.stringify({
    message: 'Go Serverless v1.0! Your function executed successfully!',
    input: event
  })
};

请参阅文档,专门Output Format of a Lambda Function for Proxy Integration

在 API Gateway 中设置集成响应

您的服务器端代码可能存在错误。

尝试在 AWS 控制台上测试您的请求。 如果有错误,它会准确地指出您的 Javascript 代码中的错误。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM