Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get aws lambda response as an HTML page

How can i get the aws lambda response as the HTML page. Please provide the step wise procedure to solve this.

like image 754
ARUNBALAN NV Avatar asked Aug 03 '15 05:08

ARUNBALAN NV


2 Answers

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.

like image 83
ARUNBALAN NV Avatar answered Nov 10 '22 21:11

ARUNBALAN NV


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.

like image 4
phoenix Avatar answered Nov 10 '22 21:11

phoenix