1 Answer
- Newest
- Most votes
- Most comments
1
There are a couple of options I can think of for solving this:
- Using CloudFront Functions: Inspect the URI and rewrite (not redirect) any requests for /foo/bar etc. to /index.html. CloudFront will serve index.html from cache if it's present, or from the origin if required.
- Using Lambda@Edge: On Origin Request for your non-API behaviors, inspect the URI (if necessary) and return the static HTML directly from Lambda - see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-generating-http-responses-in-requests.html for details on generating HTML responses in Lambda@Edge. This may not have the cost impact that you think, as the function will only be invoked in the event of a cache miss. Provided your cache hit ratio is high enough (above about 85%), this option would actually cost less than CloudFront Functions.
You could also use Lambda@Edge to perform a rewrite, if you'd prefer to store the html content in S3 rather than generate it in Lambda every time. Again, this may work out cheaper than CloudFront functions if your cache hit ratio is high enough.
Relevant content
- Accepted Answerasked 4 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago