繁体   English   中英

Lambda@Edge function 与 Nodejs 返回 502 错误 Lambda function 在标头 object 中返回了无效条目

[英]Lambda@Edge function with Nodejs return 502 ERROR The Lambda function returned an invalid entry in the headers object

我正在使用这个简单的 function 尝试 Lambda@Edge。

let express = require('express');
let serverless = require("serverless-http");
let app = express();
app.get('/', (req, res) => {
  res.send(`Hello World`);
});
app.disable('x-powered-by');
app.disable("content-length");
app.disable("etag");
module.exports.handler = serverless(app);

当我测试 lambda function 时,结果如下:

{
"statusCode": 200,
"headers": {
"content-type": "text/html; charset=utf-8",
"content-length": "189"
},
"isBase64Encoded": false,
"body": "Hello World  "
}

当我在边缘部署时,我看到这个错误:

错误 502

在 cloudwatch 上ERROR Validation error: The Lambda function returned an invalid entry in the headers object, each header entry in the headers object must be an array, header: content-type is not an array.

据此:问题在header,能帮我看看我的case是在什么地方吗?

看看这里https://aws.amazon.com/blogs/aws/running-express-applications-on-aws-lambda-and-amazon-api-gateway/

不确定 express 是否直接与 lambda 一起使用,它们有自己的风格,称为 aws-serverless-express。 尽管测试最初返回 200,但一旦部署到 Lambda@Edge,测试就会失败。

暂无
暂无

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

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