Last active
August 12, 2022 00:08
-
-
Save bendrucker/65f340e299ace46a012be2ce97af795f to your computer and use it in GitHub Desktop.
Batch update all CloudFront distributions using a specified certificate ID to a new one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
old_certificate="A..." | |
new_certificate="A..." | |
distributions=($(aws cloudfront list-distributions | jq --arg certificate $old_certificate -r '.DistributionList.Items[] | select(.ViewerCertificate.IAMCertificateId == $certificate) | .Id')) | |
echo "Distributions" | |
echo "=============" | |
printf "%s\n" "${distributions[@]}" | |
echo "\n" | |
echo "Results" | |
echo "=======" | |
for i in "${distributions[@]}" | |
do | |
previous=$(aws cloudfront get-distribution-config --id $i) | |
update=$(echo "$previous" | sed "s/$old_certificate/$new_certificate/" | jq '.DistributionConfig') | |
result=$(aws cloudfront update-distribution --id $i --distribution-config "$update" --if-match $(echo "$previous" | jq -r '.ETag')) | |
echo "$(echo $result | jq -r '.Distribution.Id + ": " + .Distribution.Status')" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This helped me a lot, thanks!