I am trying to experiment with AWS Lambda and I am using Serverless CLI for my deployment. I am using aws-nodejs template to generate my project folder.
This is the handler.js code:
'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 };
};
I am getting a successful response in JSON format. I am trying to tweak it to return HTML response. Should I change the content-type for that? If so how?
I have gone through the below questions:
and a few others as well. But all of them are using the web console and the API gateway which I am not using.
You just need to add the content headers for html
return {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: '<p>Look ma, its sending html now</p>',
}
Also, this is in one of the serverless examples in their github repo .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.