mdn / stumptown-deployer

🚢 those static Stumptown sites
Mozilla Public License 2.0
4 stars 6 forks source link

Get or create CloudFront distributions #1

Open peterbe opened 5 years ago

peterbe commented 5 years ago

After all the files have been uploaded to S3, the next thing is to get or create a CloudFront distribution. The goal is to get the domain out.

peterbe commented 5 years ago

We probably don't need answers to every question in...

Screen Shot 2019-09-23 at 8 20 51 PM

...but it would be nice to have the framework in place to control some of those things with click args or with environment variables. For example, if the branch is master you might "Price Class = Use All Edge Locations".

peterbe commented 5 years ago

Wanna put together something for this one @escattone ?

peterbe commented 5 years ago

The options are many

peterbe commented 5 years ago

We should probably never expose the fact that it's S3 + CloudFront behind the scenes. So, as a requirement, we should have a dedicated domain name for all stage deploys. I.e. we should never say "To test your deployed staging site go to https://a14tmhy55pxc8p.cloudfront.net/" Instead it should be something like "To test your deployed staging site go to https://{SUBDOMAIN}.stumptown.io/" where, if possible, {SUBDOMAIN} is the friendly name of the S3 bucket.

Eventually, if all goes according to plan, one CloudFront exception should be developer.mozilla.org.

peterbe commented 5 years ago

By the way, this blog post seems handy: https://100awsprojects.com/post/2018-01-27-s3-website-using-cf--route-53-and-python-scripts/

peterbe commented 5 years ago

I had 2 S3 buckets uploaded and prepared. I want to see how they behave side-by-side when fully configured. So I manually created a CF distribution for each bucket using the AWS console. When they were direct URLs to the S3 buckets the names are super helpful:

  1. https://stumptown-peterbe-master.s3-us-west-1.amazonaws.com/en-US/docs/Web/HTML/Element/video/index.html - clearly the "master" branch started by someone called "peterbe"
  2. https://stumptown-peterbe-lazy-load-bcd-tables.s3-us-west-1.amazonaws.com/en-US/docs/Web/HTML/Element/video/index.html - clearly the "lazy-load-bcd-tables" branch

However, the URLs you get with CloudFront, by default, completely masks this and now the two URLs are:

  1. https://d19mvvqvpwvujb.cloudfront.net/en-US/docs/Web/HTML/Element/video/index.html
  2. https://d37vkztabzp2cu.cloudfront.net/en-US/docs/Web/HTML/Element/video/index.html

I think what I'm trying to say is that it's a critical feature, before we unleash this outside the core team, that we figure out the CNAME stuff.

I don't care that much about the top-level domain but what I'd like to see is something like:

https://peterbe-lazy-load-bcd-tables.stumptown.io/en-US/docs/Web/HTML/Element/video

That's a URL I'd be proud to show my mom.

peterbe commented 5 years ago

Before I forget! One important thing about making CloudFront distributions is the origin. If you simply pick an S3 bucket instead of typing out the S3 bucket's own domain, all S3 bucket's routing rules are lost. For example:

  1. In one distribution I picked the S3 bucket from the drop-down instead of typing.
  2. In another distribution I used stumptown-peterbe-sidebar-html.s3-website-us-west-1.amazonaws.com. Now it will return the content of foo/bar/index.html if I simple go to <cloudfrontdomain>/foo/bar/

Totally cryptic but good to keep in mind.