-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudfront-invalidate
executable file
·42 lines (36 loc) · 1.25 KB
/
cloudfront-invalidate
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
#!/usr/bin/env bash
# Originally from @tsibley's gist: https://gist.github.com/tsibley/a66262d341dedbea39b02f27e2837ea8
set -euo pipefail
main() {
local domain="$1"
shift
local paths=("$@")
local distribution invalidation
echo "-> Finding CloudFront distribution"
distribution=$(
aws cloudfront list-distributions \
--query "DistributionList.Items[?contains(Aliases.Items, \`$domain\`)] | [0].Id" \
--output text
)
if [[ -z $distribution || $distribution == None ]]; then
exec >&2
echo "Unable to find CloudFront distribution id for $domain"
echo
echo "Are your AWS CLI credentials for the right account?"
exit 1
fi
echo "-> Creating CloudFront invalidation for distribution $distribution"
invalidation=$(
aws cloudfront create-invalidation \
--distribution-id "$distribution" \
--paths "${paths[@]}" \
--query Invalidation.Id \
--output text
)
echo "-> Waiting for CloudFront invalidation $invalidation to complete"
echo " Ctrl-C to stop waiting."
aws cloudfront wait invalidation-completed \
--distribution-id "$distribution" \
--id "$invalidation"
}
main "$@"