I'm new to AWS and setting up a Cloudfront distribution. From what I understand Cloudfront is designed to be used as a CDN.
I have a single-page-app that requires to communicate with the api from the same domain under /api/graphql
path pointing to a GQL server that is not hosted in AWS.
My question is is there a way to bypass the cloudfront cache for /api*
and proxy to the server?
So far I tried to create a new custom origin in the same distribution setup a cache behavior for the /api*
path to point to the custom origin, but it seems the viewer request headers are not sent to the origin server and things don't work properly.
You can add/attach a cache policy for /api*.
See here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/working-with-policies.html
This way, you can disable cache for Cloudfront and forward all headers to your origin.