Can I invalidate my Cloudfront distribution after deploy?

Beanstalk can invalidate your CloudFront distribution after every deployment when using Amazon S3 deployments. This ensures that Amazon CloudFront servers always have the most recent content. If you have not already, you can read about deploying to Amazon S3 in a separate help article.

How to invalidate CloudFront distribution

If you use Beanstalk to deploy files to an S3 bucket, and you also use that bucket as an origin for your Cloudfront Distribution, you can use the CloudFront Invalidation feature in Beanstalk to automatically invalidate that distribution.

When setting up an Amazon S3 deployment in Beanstalk, specify a valid CloudFront distribution ID in the server settings:

CloudFront Invalidation

Beanstalk will take care of the rest. After each deployment it will send a list of files to invalidate to your CloudFront distribution. This will ensure that your CDN always serves the latest versions of your files. After the invalidation was initiated by Beanstalk you can track its progress in the CloudFront Management Console.

IAM Policy for CloudFront

Create the following IAM policy in AWS Console to allow Beanstalk to trigger invalidations for your CloudFront distributions. Make sure to insert the correct account and distribution ids in the Resource section.

{
  "Sid": "VisualEditor2",
  "Effect": "Allow",
  "Action": [
    "cloudfront:ListDistributions",
    "cloudfront:GetDistribution",
    "cloudfront:GetInvalidation",
    "cloudfront:CreateInvalidation"
  ],
  "Resource": [
    "arn:aws:cloudfront::{{ ACCOUNT }}:distribution/{{ DISTRIBUTION }}"
  ]
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us