-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from asicsdigital/add_cf_invalidation
feat: add cf invalidation
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck shell=bash | ||
|
||
# Script for invalidating Cloudfront Cache. It expects an ENV var of CLOUDFRONT_ID. | ||
# First argument is a space separated list files, the second is true or false | ||
# which indicates that you would like this call to be blocking. | ||
# Eg: | ||
# ./invalidate-cloudfront-cache '/index.html /favicon.ico /js/index.js' true | ||
# ./invalidate-cloudfront-cache '/*' false | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
if [[ "$CLOUDFRONT_ID" ]]; then | ||
echo "triggering cloudfront cache invalidation" | ||
COMMAND="aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths '$1'" | ||
echo $COMMAND | ||
RETVAL=$(eval $COMMAND) | ||
echo $RETVAL | jq . | ||
RETVAL_STATUS=$(echo $RETVAL| jq -r '.Invalidation.Status') | ||
INVALIDATION_ID=$(echo $RETVAL| jq -r '.Invalidation.Id') | ||
if [[ "$RETVAL_STATUS" != "InProgress" ]] ; then | ||
echo "cloudfront invalidation not successful" | ||
exit 1 | ||
elif [[ "$INVALIDATION_ID" && "$2" == "true" ]] ; then | ||
echo "waiting for cache invalidation to complete..." | ||
COMMAND="aws cloudfront wait invalidation-completed --distribution-id $CLOUDFRONT_ID --id $INVALIDATION_ID" | ||
echo $COMMAND | ||
RETVAL=$(eval $COMMAND) | ||
echo "invalidation complete" | ||
else | ||
exit 0 | ||
fi | ||
else | ||
echo "MISSING CLOUDFRONT_ID" | ||
exit 1 | ||
fi |
This file contains 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