I am currently hosting a static single-page web application with AWS CloudFront. I would like to add a backend service for my web ui/client to communicate with so that I can serve dynamic content.
Specifically, I am concerned about same-origin policy. I have configured GoDaddy's DNS to forward traffic for my domain example.com to my AWS CloudFront endpoint using a CNAME record as described in . I am also using a CNAME to forward www.example.com to example.com. Ideally, I'd like to add another subdomain for my backend called foo.example.com, with another CNAME record pointing to it. Then, my static content could communicate with foo.example.com.
However, after reading , it seems that this still breaks the Same-Origin Policy. To be considered the same origin, the entire domain (including the subdomain) must match. CORS (see ) doesn't seem like a viable option since it can't be used within JS and thus seems to be limited to more static content or Iframes. Anyways, it seems really heavy-handed when all I really need is for two sub-domains that I own to communicate with each other.
How is this usually done? I'd like to avoid setting up my own load-balancer in front of CloudFront since I want to utilize its speed and efficiency as a global CDN.