Multiple Cloudfront Origins with Behavior Path Redirection

Update: the original answer, shown below, is was accurate when written in 2015, and is correct based on the built-in behavior of CloudFront itself. Originally, the entire request path needed to exist at the origin. If the URI is /download/images/cat.png but the origin expects only /images/cat.png then the CloudFront Cache Behavior /download/* will not do … Read more

How to choose an AWS profile when using boto3 to connect to CloudFront

I think the docs aren’t wonderful at exposing how to do this. It has been a supported feature for some time, however, and there are some details in this pull request. So there are three different ways to do this: Option A) Create a new session with the profile dev = boto3.session.Session(profile_name=”dev”) Option B) Change … Read more

Cloudfront redirect www to naked domain with ssl [closed]

To host website on AWS so that: https://www.example.com, http://www.example.com and http://example.com all redirect to https://example.com you need to: Create two S3 buckets named: example.com and www.example.com. Turn on the Static Website Hosting on these two buckets. Configure redirect in bucket www.example.com to: https://example.com. In the bucket properties choose Static Website Hosting => Redirect all requests … Read more

Correct S3 + Cloudfront CORS Configuration?

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 … Read more

CloudFront + S3 Website: “The specified key does not exist” when an implicit index document should be displayed

I’ll go out on a limb and say that the specified key doesn’t technically exist, so the error message is technically accurate but doesn’t tell the whole story. This should be an easy fix. S3 buckets have two¹ endpoints, “REST” and “website.” They have two different feature sets. The web site endpoint provides magical resolution … Read more

Amazon CloudFront Latency

CloudFront attempts to fetch uncached content from the origin server in real time. There is no “replication delay” or similar issue because CloudFront is a pull-through CDN. Each CloudFront edge location knows only about your site’s existence and configuration; it doesn’t know about your content until it receives requests for it. When that happens, the … Read more