Forked from bendrucker/cloudfront-batch-certificates.sh
Created
January 25, 2021 14:15
-
-
Save rcadecaro/0d417967c69666e11402cd0957c54750 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 hidden or 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