-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_ping_endpoint
More file actions
executable file
·43 lines (34 loc) · 1.05 KB
/
Copy path_ping_endpoint
File metadata and controls
executable file
·43 lines (34 loc) · 1.05 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
#!/usr/bin/env bash
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 [[ -z "${TF_VAR_API_TRIGGER_SECRET:-}" ]]; then
echo "TF_VAR_API_TRIGGER_SECRET must be set in .env to ping the API endpoint." >&2
exit 1
fi
echo "Fetching API endpoint from terraform outputs..."
api_url="$(tofu output -raw api_gateway_url 2>/dev/null || true)"
if [[ -z "${api_url}" ]]; then
echo "Failed to resolve api_gateway_url. Ensure you've run 'source .env' and 'tofu apply'." >&2
exit 1
fi
echo "Pinging ${api_url}"
response="$(curl --fail --show-error --silent --header "x-sbn-check-secret: ${TF_VAR_API_TRIGGER_SECRET}" "${api_url}")" || {
echo "Request failed." >&2
exit 1
}
if command -v jq >/dev/null 2>&1; then
echo "${response}" | jq '.'
else
echo "${response}"
fi
echo "Lambda invocation succeeded."