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
We can now configure a simple API gateway endpoint to use the above lambda function to output static html. From API gateway, click on Create API. Name the new API as htmldemo. From Actions menu, click on Create Method and select GET.
The easiest way to set custom HTTP status code is to setup a Lambda Proxy Integration in API Gateway. In API Gateway > Resource > Actions Dropdown > Create Method > tick Lambda Proxy Integration and select appropriate Lambda function. For async functions just return with an object with statusCode and body .
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',
}
}
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
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