- Newest
- Most votes
- Most comments
Yes, it is possible to return a default HTML page when the AWS integration response is a 404 error. To do this, you will need to set up an error handling mechanism in your API Gateway REST API.
One way to handle 404 errors is to use an HTTP integration with a mock integration to return a default HTML page. To do this, you can create a mock integration in your API Gateway REST API and specify an HTTP status code of 404 and a response body that contains the HTML for the default page that you want to return.
Then, you can set up a catch-all route in your API Gateway REST API that routes all requests to the mock integration. This catch-all route can be set up using a wildcard path parameter, such as {proxy+}. This will catch any request that does not match any of the other routes in your API, including requests for non-existent keys in your S3 bucket.
Alternatively, you can configure your S3 bucket to return a default page for 404 errors. To do this, you can specify an error document in the S3 bucket's static website hosting configuration. When a request is made for a non-existent key, S3 will return the error document instead of the NoSuchKey error code.

I should have clarified, but the way that the apigateway aws integration s3 proxy works is:
I am confused by your answer-- if I got a 404 error from the aws integration, how would I then route back to the mock http integration to return a 404 response?
Also as mentioned in my post, I have already set the error document in the s3 buckets static website hosting config, but I still get the nosuchkey xml instead of the error page. Is there anything else that I would need to configure on the s3 bucket to ensure that the bucket returns the error page instead?