Reputation: 551
I'm trying to return a webpage from my python lambda ftn, using API GW. Instead, I'm getting my page embeded in a tag within the body, instead of the return value being the full page ( header, body, etc... without the pre>
Any suggestions what I might be doing wrong
Thanks
Upvotes: 18
Views: 27949
Reputation: 309
You have to configure the API Gateway to return the proper Content-Type.
$input.path('body')
if your json is:.
{
"statusCode": 200,
"body": "<html><body><h1>Test</h1></body></html>"
}
Here's a more detailed article on how to return html from AWS Lambda
Upvotes: 9
Reputation: 89
try:
response_body = "<HTML><Title>Title</Title></HTML>"
finally:
return {
"statusCode": 200,
"body": response_body,
"headers": {
'Content-Type': 'text/html',
}
}
This just code illustration of David Lin answer
Upvotes: 8
Reputation: 13353
The <pre>
tag you are seeing is the browser trying to show you the text returned from server. It is not part of the returned from the Lambda function.
To get it working you need to get the lambda function set the response HTTP header with Content-Type: 'text/html'
for example:
response = {
"statusCode": 200,
"body": content,
"headers": {
'Content-Type': 'text/html',
}
}
Upvotes: 36