![](/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.