I have an AWS API Gateway API with CORS enabled and a custom domain set-up. Direct API access via the execute-api
endpoints is working and I get no CORS issues in the browser. Access via the custom domain api.example.com
which I also configured, is working in principle, but not in the browser, where I get CORS:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
When setting up the custom domain, API Gateway configures its own CloudFront distribution which is somewhat internal and I do not see how to configure it or if this is even possible, it does not show up in my list of CloudFront distributions, which is expected. From the AWS docs:
The CloudFront distribution created by API Gateway is owned by a region-specific account affiliated with API Gateway
I found these answers https://stackoverflow.com/a/52435619/4556546 and https://stackoverflow.com/a/51463965/4556546 that describe how to solve the problem with a normal CloudFront distribution. I am, however wondering:
- Have I missed something in configuring the custom domain and its associated CloudFront distribution?
- In what circumstances would I choose the custom domain with its internal CloudFront distribution over running my own CloudFront distribution that I can configure? (I already have a CloudFront distribution that I use for other parts of my app.) Are there pricing implications?