Amazon CloudFront

Simple CloudFront Invalidation of a Single File via HTTP 7


Amazon Web Services ButtFrontI found a great post by Clay Loveless who wrote a PHP script to batch invalidate files files on an Amazon Web Services CloudFront distribution. You rock, Clay. Amazon doesn’t even let us do that (yet?) via the AWS Mangament Console.

Until now, when I wanted to manually invalidate a single file, I had to fire up CloudBerry S3 Explorer and scroll through thousands of files to get to the one I wanted to invalidate. For automated on-the-fly batch sync and CloudFront invalidation, I still rely on the excellent s3cmd command-line tool.

I’m not a developer, but I can lightly hack my way around PHP code – especially when it’s as clean as Clay’s.  I took his excellent script one small step farther to allow invalidating a single file via HTTP (using your browser) by including the to-be-invalidated filename in a URL, with the ability to optionally pass my CloudFront Distribution ID via a separate variable in the URL (handy for those of us managing multiple distributions). I highly recommend making sure you place this file in a password protected area of your website.

So here’s my modified version of Clay’s PHP script providing a simple way to invalidate a single file on CloudFront using your browser: