Amazon CloudFront Invalidation Automation

Amazon CloudFront allows you to remove one or multiple files from all edge locations prior to the expiration date set on those files. The invalidation feature is helpful in unexpected circumstances, for instance, an occasional update to your website’s CSS file, in which you need to remove the file from Amazon CloudFront. Invalidation can also be helpful in the event that offensive or potentially harmful material needs to be removed before the specified expiration time.

Note: Invalidation requests for the first 1,000 files each month are provided at no additional charge; above this level, there is a $0.005 charge for invalidating each additional file.

Challenges:

1. The whole Cloudfront invalidation configuration is done using a cloud formation template.

2. All the required configuration details can be mentioned in the cloud formation template.

3. The manual process of deployment was updated to cloud formation automation.

Solution Overview:

1. A Cloudfront invalidation to specify CloudFront distributions, cloudFrontObjectPaths, cron expression Parameter.

2. A Cloudfront invalidation Automation can be fully automated by using Cloudfomartion. In this example, I show you how to schedule Cloudfomartion Invalidation automation.

Git Repo: https://github.com/kkpkishan/cloudfront-invalidation-scheduler.git

Steps:

1. Create Cloudfront invalidation automation using CloudFormation.

This example consists of four CloudFormation resources:

1. An IAM Role: AWS Lambda needs a service role to do its work in your AWS account. It uses an AWS-managed IAM policy to minimize the work to be done here.

2. A CloudWatch event executes AWS lambda to CloudFront invalidation resources each day at eighteen o’clock. The syntax used by AWS Lambda is the same as in CloudWatch Events.