I have CloudFront setup which is setup to serve various subdomains under my domain.
ex.
http://demo1.mydomain.com/test.html, and
http://demo2.mydomain.com/index.html
can be two requests which are served by the CloudFront.
Now the issue here is with CloudFront caching. It caches the content based on path ie. in the above examples ("/test.html" and "/index.html").
This creates a problem that if two subdomains having same path, content which will get cached for a given path in one subdomain and will also be served from cache (same path) in other subdomain. ex.
http://demo1.mydomain.com/example.html
http://demo2.mydomain.com/example.html
The second request here will serve the cached content of first one.
Can I configure CloudFront to include subdomain when caching? This way I can avoid same path conflicts across subdomain.
Thanks
I had the same challenge, and solved it using headers.
In details: We are indicating our tenants by subdomain id:
<id>.domain.com
We wanted to store a different cached value for each tenant. For example:
123.domain.com/get-config and 456.domain.com/get-config need to return different cached values.
As a solution, since cloudfront doesn't supply an indication based on sub-domains, we based on headers.
In your case, you can pass a header named appName and give it values: demo1, demo2 etc.
Cloudfront will host different cache values based on that header.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-selecting
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