On June 26, 2014 AWS released proper Vary: Origin behavior on CloudFront so now you just
-
Set a CORS Configuration for your S3 bucket including
<AllowedOrigin>*</AllowedOrigin>
-
In CloudFront -> Distribution -> Behaviors for this origin
- Allowed HTTP Methods: +OPTIONS
- Cached HTTP Methods +OPTIONS
- Cache Based on Selected Request Headers: Whitelist the
Origin
header.
-
Wait for ~20 minutes while CloudFront propagates the new rule
Now your CloudFront distribution should cache different responses (with proper CORS headers) for different client Origin headers.