簡體   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