[英]How to return HTML code from Lambda function in NodeJS?
我有以下 Lambda function。
当调用 function 时,我需要返回一些自定义 html。
我试过了:
exports.handler = async (event, context, callback) => {
const response = {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: String("Hi there !"),
};
return response;
}
但是在调用 function 时,出现以下错误: Lambda function 在标头 object 中返回了一个无效条目:标头 object 中的每个 header 条目都必须是一个数组。 我们目前无法连接到此应用程序或网站的服务器。
我从 AWS 蓝图中获取了代码:
来自 AWS 的原始代码:
请问有人知道我做错了什么吗?
谢谢。 干杯,
您似乎使用了常规的 AWS Lambda 蓝图。 Edge Lambda 功能不同,例如状态代码在status
中返回,而不是在statusCode
中返回。
基于文档示例:
exports.handler = (event, context, callback) => {
const response = {
status: '200',
statusDescription: 'OK',
headers: {
'cache-control': [{
key: 'Cache-Control',
value: 'max-age=100'
}],
'content-type': [{
key: 'Content-Type',
value: 'text/html'
}]
},
body: "some HTML content here",
};
callback(null, response);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.