How can i get the aws lambda response as the HTML page. Please provide the step wise procedure to solve this.
Store the HTML markup in a variable and return it to avoid the text being wrapped in quotes. First store your HTML markup in a variable in the lambda function then return it. For example in Node.js:
context.succeed({ variableHTML: myContentHtml })
Here is an example of the mapping template:
#set($inputRoot = $input.path('$'))
$inputRoot.variableHTML .
Here variableHTML
contains the HTML markup passed from the lambda function. After that you needed to create an Response model for HTTP Status, which is accessible through Method Response. Here set the Response model Content-Type as text/html. Then you'll get the HTML page without quotes and the browser recognizes it as HTML.
You don't need Lambda to print out HTML.
Adding the HTML code:
go to your GET method -> Integration Response -> Body Mapping Templates
delete application/json (by default)
add text/html mapping
in the empty field to the right, just paste your HTML (delete anything else)
You will also need to update the content type in the Method Response:
expand 200 response
under Response Body for 200, delete application/json and add text/html with an empty model
Then just deploy your API and you're done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With