I am using API Gateway to directly serve up Lambda functions as a web application. I do the needed mappings for text/html and everything is working great.
I have reason to want proxy integration on a few pages so I tried to follow this how-to.
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html
It’s working fine BUT the browser is displaying a JSON object, not a web page. Can I use proxy integration to serve up a web page directly (text/html), not a JSON object?
You need to send back the headers
with "content-type":"text/html"
as one of the entries.
You can also use a framework like Lambda API to handle this for you: https://github.com/jeremydaly/lambda-api
The response object from Lambda should look like this:
{
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": { "headerName": "headerValue", ... },
"body": "..."
}
Documentation here: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
Brilliant, thanks! I will try the standard solution and also take a close look at your API framework. Appreciate the help.
@jeremydaly, I just wanted to follow up to say your solution worked perfectly and I really appreciate your help. Thanks again.
1 Like