Use Lambda to Fix CloudFront/S3 CORS Issues
If you use S3 to serve static assets, you're going to have to configure S3 to deal with CORS issues.
Unfortuantly, S3 doesn't return Vary: Origin
unless an Origin
request header is present. This
causes CORS issues for browsers like Chrome since the original cached response from the GET request
will get reused for CORS evaluation due to the lack of Vary: Origin
.
The solution is to use a Lambda@Edge function to add the correct response headers from S3.
Steps to set up Lambda/CloudFront/S3: