Working with the Amazon CloudFront CDN

This is a compilation of things learned while setting up Amazon CloudFront as a CDN for my Wordpress site as well as using it as software distribution network.

CNAMEs

Adding a CNAME

A CloudFront distribution can be used with ten different CNAMEs. Adding a CNAME is simple enough if you keep in mind that configuring the CNAME in DNS is not sufficient; each CNAME must be added to the distribution’s properties, too.

Removing a CNAME

Removing a CNAME is equally simple, but there is one caveat: you might have CSS or other objects in the CDN’s cache that still refer to the CNAME. Such objects must be deleted from CloudFront’s cache. See below how to do that.

Deleting an Object from the Cache

If you use CloudFront as a distribution mechanism for downloads like I do, at some point in time you want to update your files - and you want that update reflected in the CDN quickly.

For a long time this was not possible with CloudFront. Amazon suggested lame workarounds involving giving each version a unique name, but then in 2010 they added this essential feature. Unfortunately, it is not available from the AWS Management Console, only via API calls. But there are a tools that make use of the API to provide the purge functionality.

W3 Total Cache

This Wordpress plugin comes with support for CDNs and Amazon CloudFront. To purge an object click “CDN” and then “Purge”:

W3 Total Cache - CDN page

A popup window opens. Enter the relative path without leading slash and click “Purge”.

Bucket Explorer

Bucket Explorer is a commercial tool for managing Amazon S3 and CloudFront. It comes with a fully functional 30-day trial version which I used for my tests.

After starting the tool and entering access key ID and secret key Bucket Explorer lists my S3 buckets. To manage CloudFront, click “Distribution”. In the window that pops up, right-click your distribution and select “Get CloudFront Invalidation List”:

Distribution in Bucket Explorer

The invalidation list window pops up and displays both past and current invalidations (read: deletes). You can create new invalidations and check if an invalidation is still being processed by the CDN or if it is completed:

Invalidation List in Bucket Explorer

Processing Time

Each change to a CloudFront distribution needs to travel through the CDN’s network to all nodes before it is activated. That may take some time; my changes were through in 10-20 minutes.

Comments

Related Posts

How to Reduce Bandwidth Usage and Optimize Website Performance with W3 Total Cache and Amazon CloudFront

How to Reduce Bandwidth Usage and Optimize Website Performance with W3 Total Cache and Amazon CloudFront
My website is hosted by Rochen, a company whose services I am very happy with. For reasons I understand they do not offer unlimited data transfer. My account, for example, comes with 50 GB per month. That is a lot and enough for most sites, including mine at this point in time. But I am selling software, and if a big news site writes about SetACL Studio the least of all things I want to happen is that Rochen suspends my account because the transfer limit has been reached.
Website

Latest Posts