Get aws lambda response as an HTML page

2019-02-03 04:27发布

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

2条回答
家丑人穷心不美
2楼-- · 2019-02-03 04:46

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.

查看更多
We Are One
3楼-- · 2019-02-03 04:50

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.

查看更多
登录 后发表回答