Update AWS CloudFront configuration using AWS CLI
Table of Contents
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 #
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.