![](/img/trans.png)
[英]AWS Lambda with API gateway and Node.js returning HTTP 502
[英]Returning HTML response without API gateway in AWS Lambda for Node template
我正在尝试使用 AWS Lambda,并且我正在使用无服务器 CLI 进行部署。 我正在使用 aws-nodejs 模板来生成我的项目文件夹。
这是 handler.js 代码:
'use strict';
module.exports.hello = async (event, context) => {
return {
statusCode: 200,
body: {
"message":
'Hello World! Today is '+new Date().toDateString()
}
};
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};
我得到了 JSON 格式的成功响应。 我正在尝试调整它以返回 HTML 响应。 我应该为此更改内容类型吗? 如果是这样怎么办?
我已经完成了以下问题:
还有其他一些人。 但是他们都在使用我没有使用的 Web 控制台和 API 网关。
您只需要为 html 添加内容标题
return {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: '<p>Look ma, its sending html now</p>',
}
此外,这是在他们的 github repo中的无服务器示例之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.