forked from Ducharme/infraAsCodeShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_react_resources.sh
More file actions
26 lines (21 loc) · 1.48 KB
/
delete_react_resources.sh
File metadata and controls
26 lines (21 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
# TODO: Not tested yet
echo "Calling aws cloudfront delete-cloud-front-origin-access-identity"
CDN_CALLER_REFERENCE=$S3_REACT_WEB.s3.$AWS_REGION_VALUE.amazonaws.com
echo "Calling cloudfront update-distribution (can take a while)"
JQF=".DistributionList.Items[] | select(.Origins.Items[0].Id == \"$CDN_CALLER_REFERENCE\") | .Id"
DIST_ID=$(aws cloudfront list-distributions | jq "$JQF" | tr -d '"')
CONFIG_JSON=tmp_distribution-config-$DIST_ID.json
aws cloudfront get-distribution-config --id $DIST_ID | jq '. | .DistributionConfig' > $CONFIG_JSON
sed -i 's@"Enabled": true,@"Enabled": false,@g' $CONFIG_JSON
ETAG=$(aws cloudfront get-distribution-config --id $DIST_ID | jq '.ETag' | tr -d '"')
aws cloudfront update-distribution --id $DIST_ID --if-match $ETAG --distribution-config file://$CONFIG_JSON
aws cloudfront wait distribution-deployed --id $DIST_ID
echo "Calling cloudfront delete-distribution"
ETAG=$(aws cloudfront get-distribution-config --id $DIST_ID | jq '.ETag' | tr -d '"')
aws cloudfront delete-distribution --id $DIST_ID --if-match $ETAG
OAI_CALLER_REFERENCE=access-identity-$CDN_CALLER_REFERENCE
JQF=".CloudFrontOriginAccessIdentityList.Items[] | select(.Comment == \"$OAI_CALLER_REFERENCE\") | .Id"
OAI_ID=$(aws cloudfront list-cloud-front-origin-access-identities | jq "$JQF" | tr -d '"')
ETAG=$(aws cloudfront get-cloud-front-origin-access-identity-config --id $OAI_ID | jq '.ETag' | tr -d '"')
aws cloudfront delete-cloud-front-origin-access-identity --id $OAI_ID --if-match $ETAG