Add CDN cache invalidation to deploy scripts.
This commit is contained in:
28
operations/invalidate-cdn-cache.sh
Executable file
28
operations/invalidate-cdn-cache.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
echo "Looking up CloudFront distribution ID for Personal Measure ${TARGET_ENV} environment."
|
||||
cloudfront_distribution_id=$(\
|
||||
aws cloudfront list-distributions \
|
||||
--query "DistributionList.Items[?starts_with(Comment, 'Personal Measure ${TARGET_ENV}')].Id | [0]" \
|
||||
| sed -e 's/^"//' -e 's/"$//'
|
||||
)
|
||||
|
||||
if [[ -z "${cloudfront_distribution_id}" ]]; then
|
||||
>&2 echo "Unable to find CloudFront distribution for domain ${TARGET_ENV}."
|
||||
exit 3
|
||||
fi
|
||||
|
||||
echo "Found distribution ID ${cloudfront_distribution_id}."
|
||||
|
||||
echo "Invalidating the CloudFront cache for ${TARGET_ENV}."
|
||||
invalidation_id=$(aws cloudfront create-invalidation \
|
||||
--query 'Invalidation.Id' \
|
||||
--distribution-id "${cloudfront_distribution_id}" \
|
||||
--paths '/index.html')
|
||||
|
||||
if [[ $? -ne 0 || -z "${invalidation_id}" ]]; then
|
||||
>&2 echo "Unable to create the CloudFront invalidation."
|
||||
else
|
||||
echo "Successfully created invalidation ${invalidation_id}."
|
||||
fi
|
||||
|
||||
echo "Done."
|
Reference in New Issue
Block a user