Skip to content

Instantly share code, notes, and snippets.

@ahmed-abdelazim
Last active July 31, 2024 13:14
Show Gist options
  • Select an option

  • Save ahmed-abdelazim/d5aa4dea6ecb5dbbff94ce1f5c1f32ff to your computer and use it in GitHub Desktop.

Select an option

Save ahmed-abdelazim/d5aa4dea6ecb5dbbff94ce1f5c1f32ff to your computer and use it in GitHub Desktop.

Revisions

  1. ahmed-abdelazim revised this gist Apr 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cloudfront.sh
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,6 @@ jq --arg NEW_ORIGIN "$NEW_ORIGIN" '.Distribution.DistributionConfig.Origins.Item
    jq --arg NEW_ORIGIN "$NEW_ORIGIN" '.Distribution.DistributionConfig.Origins.Items[0].DomainName=$NEW_ORIGIN' | \
    jq --arg NEW_ORIGIN "$NEW_ORIGIN" '.Distribution.DistributionConfig.DefaultCacheBehavior.TargetOriginId=$NEW_ORIGIN' | \
    jq .Distribution.DistributionConfig > config.json
    aws cloudfront update-distribution --id $CLOUDFRONT_DISTRIBUTION_ID --distribution-config "file://config.json" --if-match $ETAG
    aws cloudfront update-distribution --id $CLOUDFRONT_DISTRIBUTION_ID --distribution-config "file://config.json" --if-match $ETAG > /dev/null
    aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
    rm config.json
  2. ahmed-abdelazim created this gist Apr 9, 2022.
    12 changes: 12 additions & 0 deletions cloudfront.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #!/bin/bash
    CLOUDFRONT_DISTRIBUTION_ID=E2C3RNL2F4MRMQ
    NEW_ORIGIN="origin2-zaid.s3.us-west-2.amazonaws.com"
    ETAG=`aws cloudfront get-distribution --id $CLOUDFRONT_DISTRIBUTION_ID | jq -r .ETag`
    aws cloudfront get-distribution --id $CLOUDFRONT_DISTRIBUTION_ID | \
    jq --arg NEW_ORIGIN "$NEW_ORIGIN" '.Distribution.DistributionConfig.Origins.Items[0].Id=$NEW_ORIGIN' | \
    jq --arg NEW_ORIGIN "$NEW_ORIGIN" '.Distribution.DistributionConfig.Origins.Items[0].DomainName=$NEW_ORIGIN' | \
    jq --arg NEW_ORIGIN "$NEW_ORIGIN" '.Distribution.DistributionConfig.DefaultCacheBehavior.TargetOriginId=$NEW_ORIGIN' | \
    jq .Distribution.DistributionConfig > config.json
    aws cloudfront update-distribution --id $CLOUDFRONT_DISTRIBUTION_ID --distribution-config "file://config.json" --if-match $ETAG
    aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
    rm config.json