-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_cloudfront_invalidate
More file actions
executable file
·47 lines (36 loc) · 1.13 KB
/
Copy path_cloudfront_invalidate
File metadata and controls
executable file
·47 lines (36 loc) · 1.13 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
#
# Create a CloudFront invalidation for the deployed distribution.
set -euo pipefail
IFS=$'\n\t'
if [[ ! -f ".env" ]]; then
echo "Missing .env file. Copy .env-template and configure required values." >&2
exit 1
fi
# shellcheck disable=SC1091
source .env
if ! command -v tofu >/dev/null 2>&1; then
echo "OpenTofu (tofu) is not installed or not in PATH." >&2
exit 1
fi
if ! command -v aws >/dev/null 2>&1; then
echo "AWS CLI not found. Install it to run invalidations." >&2
exit 1
fi
distribution_id=$(tofu output -raw cloudfront_distribution_id 2>/dev/null || true)
if [[ -z "${distribution_id}" ]]; then
echo "Failed to resolve cloudfront_distribution_id. Deploy infrastructure first." >&2
exit 1
fi
if [[ $# -gt 0 ]]; then
paths=("$@")
else
paths=("/latest.txt")
fi
caller_ref="invalidate-$(date +%s)"
echo "Creating invalidation on distribution ${distribution_id} for paths: ${paths[*]}"
aws cloudfront create-invalidation \
--distribution-id "${distribution_id}" \
--paths "${paths[@]}" \
--caller-reference "${caller_ref}" >/dev/null
echo "Invalidation submitted. Caller reference: ${caller_ref}"