-
Notifications
You must be signed in to change notification settings - Fork 1
/
invalidate-cloudfront.sh
executable file
·62 lines (55 loc) · 2.27 KB
/
invalidate-cloudfront.sh
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# shellcheck disable=SC2154
set -e
# NEW_CHANGES=""
# # See if we've got any output from the S3 upload script
# if [ -f "/tmp/$GITHUB_SHA.tmp" ]; then
# cat "/tmp/$GITHUB_SHA.tmp"
# CHANGES=$(grep upload /tmp/$GITHUB_SHA.tmp | awk '{print $2}')
# # Need to ensure that each change starts with "/" either by removing
# # a leading full-stop or by adding a missing "/"
# for change in $CHANGES
# do
# if [[ ${change::1} == "." ]]; then
# new_change=${change:1}
# elif [[ ${change::1} == "/" ]]; then
# new_change=change
# else
# new_change="/${change}"
# fi
# NEW_CHANGES="$NEW_CHANGES $new_change"
# done
# # Clean up ...
# rm "/tmp/$GITHUB_SHA.tmp"
# fi
# if [ "$NEW_CHANGES" == "" ]; then
# NEW_CHANGES="/*"
# fi
# Intelligent cache invalidation seems to cause problems when error responses are cached
# since the intelligent invalidation doesn't always touch those paths. For now, revert to
# invalidating the entire site.
NEW_CHANGES="/*"
echo "======== CREATING INVALIDATION ========"
echo "--distribution-id \"$CF_DIST_ID_STATIC_LO\" --paths $NEW_CHANGES"
invID=$(aws --profile "$AWS_STATIC_SITE_PROFILE" cloudfront create-invalidation \
--distribution-id "$CF_DIST_ID_STATIC_LO" --paths "$NEW_CHANGES" --query Invalidation.Id --output text)
export invID
echo "======== INVALIDATION ID ========"
echo "${invID}"
echo "======== POLLING COMPLETED INVALIDATION ========"
# Increasingly, a single call to cloudfront wait invalidation-completed has been erroring
# out with "max attempts exceeded". We now run this in a do loop to ensure that we repeat
# the call until it is all finished.
until aws --profile "$AWS_STATIC_SITE_PROFILE" cloudfront wait invalidation-completed \
--distribution-id "$CF_DIST_ID_STATIC_LO" --id "${invID}" 2>/dev/null
do
# Still waiting - output some progress
echo "Still waiting ..."
aws --profile "$AWS_STATIC_SITE_PROFILE" cloudfront get-invalidation \
--distribution-id "$CF_DIST_ID_STATIC_LO" --id "${invID}"
sleep 10
done
# and final confirmation
aws --profile "$AWS_STATIC_SITE_PROFILE" cloudfront get-invalidation \
--distribution-id "$CF_DIST_ID_STATIC_LO" --id "${invID}"
echo "======== INVALIDATION COMPLETED ========"