Distribute video fast and cheap

Earlier this month, I wrote a tutorial for setting up a Google Cloud Video CDN service for your website. After running this setup for a few days, I quickly realized how expensive it is to run a GCS CDN. Google charges you for load balancers, static IP addresses, and more.

Amazon offers similar service but without these networking fees. Cloudfront is marginably more expensive than Google. When it all comes out, Amazon is cheaper.

If you are a large business and somehow found your way to this post, know that Google will server you better as a CDN if you are through-putting large amounts of video. Amazon and Azure are optimized for many more small files while Google and Akamai tend to cater towards massive throughput of larger files.

That being said, Cloudfront is highly capable of running a medium business website with tons of video and serving it up all around the world. The creator friendly video site vidme uses cloudfront to server up their entire library. I bet that’s expensive!

What will this tutorial provide?

  • Create S3 buckets for storing video
  • Securing Cloudfront with SSL and custom CNAME
  • Configuring Cloudfront distributions
  • Running through CloudFlare
  • Further Notes

Creating Buckets and Uploading Video

First we need to create buckets that are properly configured to host our video. Let’s take a look at the permissions we need to make these buckets work.

ScAMdsM-min.png

To enable public permissions, simply set the Everyone permissions to read for objects and object permissions.

Alternativey, you can add a custom bucket policy as follows. This is what I use

{
 "Version": "2012-10-17",
 "Statement": [
 {
 "Sid": "AddPerm",
 "Effect": "Allow",
 "Principal": "*",
 "Action": "s3:GetObject",
 "Resource": "arn:aws:s3:::cdn.whitkennedy.com/*"
 }
 ]
 }

Now we can create a folder strucutre within our bucket and start uploading video to S3. Keep in mind that there are tons of WordPress plugins that allow direct uploading to S3 from WordPress. I like to use Cyberduck.

Obtaining SSL Certificate from Amazon

o8MrKIo.png

Before we spawn a distribution, we need to obtain a SSL certificate so that our files are not server over http. We can either obtain a free certificate from something like sslforfree.com or we can use the better more permenant option, that being obtaining a certificate from Amazon that handles autorenewal.

Head over to certificate manager. Be aware that these certificates will only work for CloudFront and Elastic Beanstalk.

Hu3wmHT-min.png

Important Note: When you request a certificate for your domain, Amazon will send a confirmation email to [email protected] You MUST have [email protected] setup and working BEFORE you request the SSL cert from Amazon. Otherwise this will not work. Once you add the cert, you will recieve an email with an activation link.

After we click the activation link, we will now have our proper SSL cert for our custom cname. Now lets get that CloudFront distribution working!

Spawning CloudFront Distribution

Create a Web Distribution.

9ow7ZjB-min.png

Select your S3 bucket to pull from. This is where your content is stored and uploaded to.

1onJpNo-min.png

Only setting here I changed was to redirect http for https.

erhtgHm-min.png

Here I have added my custom CNAME and also added my custom SSL to the selection.

S8HstWY-min.png

Further Settings

LCjeCx5-min.png

Now click Create Distribution. Amazon says this takes 15 minutes but its more like half an hour.

DNS

Add your CNAME to your DNS and use your new CloudFront url as the alias.

cKoRtNb.png

CloudFlare

I still need to do more testing as to how effective this solution is. But it does work! Technically speaking, you can have more control over your CloudFront CDN if its running through CloudFlare. This will have almost no impact on performance but I have yet to fully test if the CloudFlare reverse proxy system confuses Amazon Edge server. If you don’t want to use CloudFlare Reverse Proxy, tick the orange cloud and the redirect will be DNS only.

Notes

This is much cheaper than Google on the small scale. It starts to even out when you get to a larger scale however. I like Amazon AWS, and they definantly beat out Google in terms of features for the cheap CDNs.

This is not a CDN for your entire website, but it very easily could be. I use Amazon just for video hosting and podcast episodes. I use CloudFlare for .html .js .css and I use Photon for .jpg and .png. Any larger .gif files I host on imugur. This is my 2017 hacked together CDN. It works well!