gpt4 book ai didi

node.js - 无服务器 502 网关错误

转载 作者:行者123 更新时间:2023-12-02 17:16:24 24 4
gpt4 key购买 nike

我能够按照文档创建一个简单的无服务器函数,但是当我添加 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

$ 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
})
};

See docs具体来说用于代理集成的 Lambda 函数的输出格式

Set up an Integration Response in API Gateway

关于node.js - 无服务器 502 网关错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54164066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com