Skip to main content
  1. Posts/

Update AWS CloudFront configuration using AWS CLI

·218 words·2 mins
aws cloudfront aws cli
Daniel Ancuta
Author
Daniel Ancuta
Backend team lead, with 16+ years of hands-on experience with modern technologies, as well as 4+ years of experience in leading of development teams. Let us get in touch!

Regardless of whether you just need to make a quick manual change or it’s part of your CI/CD process, AWS CLI can be very useful for both scenarios.

Let’s dig into updating AWS CloudFront with AWS CLI!

Prerequisite #

  1. You have AWS CLI installed
  2. You have jq installed (not required but useful)

Update AWS CloudFront configuration using AWS CLI #

Getting ETag #

A Distribution ETag is required to update its configuration

aws cloudfront get-distribution-config --id {ID-OF-DISTRIBUTION} | jq '. | .ETag'

Take note of the ETag value; you will need it later.

Getting CloudFront configuration #

aws cloudfront get-distribution-config --id {ID-OF-DISTRIBUTION} | jq '. | .DistributionConfig' > /tmp/cloudfront-{ID-OF-DISTRIBUTION}

Now you can modify configuration file.

Updating CloudFront configuration #

Now we will send the modified configuration file to the AWS CloudFront distribution.

aws cloudfront update-distribution --id {ID-OF-DISTRIBUTION} --if-match {ETag-value} --distribution-config file:///tmp/cloudfront-{ID-OF-DISTRIBUTION}

That’s it! Your changes got deployed and applied.

Troubleshooting #

The If-Match version is missing or not valid for the resource.

If you see this error, you have used the wrong ETag value for --if-match. After you run update-distribution, your CloudFront’s ETag will change, and you will need to obtain it again.

The End #

That’s it! I hope you found something useful in this post! If your company needs some help with AWS, get in touch.