I created a cloudfront distribution with the below details:
- Origin1 -> S3Bucket
- Origin2 -> APIGateway endpoint with base /Prod appended
- DefaultBehavior ->
*, Origin1, CachingEnabled, no Origin Policy - APIBehavior ->
/api/*, Origin2, CachingDisabled
With the above setup, I see the desired behavior i.e., all requests to any path starting with /api/ is redirected to Origin2 and the rest to Origin1. Also the caching policy works fine.
But now I wish to forward headers/query parameters to origin without affecting the caching schema. So for Origin2's behavior (/api/*), I added AllViewer Origin policy (Forwards all headers, query requests etc.). But now the /api/* calls are redirected to Prod/api/* and Origin1 is used instead of Origin2.
This seems so counterintuitive to me, could anyone please enlighten if I'm missing something?