2022-11-08 10:43:17 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Usage: ./aws-logs.sh <region>
|
|
|
|
|
2022-12-08 10:55:56 -05:00
|
|
|
set -euo pipefail
|
|
|
|
shopt -s inherit_errexit
|
|
|
|
|
|
|
|
echo "Using AWS region: ${1}"
|
2023-07-13 10:28:33 -04:00
|
|
|
echo "Using Constellation UID: ${2}"
|
2022-11-08 10:43:17 -05:00
|
|
|
|
2022-11-10 08:17:04 -05:00
|
|
|
controlInstances=$(
|
2023-07-13 10:28:33 -04:00
|
|
|
aws ec2 describe-instances \
|
|
|
|
--filters "Name=tag:constellation-uid,Values=${2}" "Name=tag:constellation-role,Values=control-plane" \
|
2022-11-10 08:17:04 -05:00
|
|
|
--region "${1}" \
|
|
|
|
--no-paginate \
|
2023-07-13 10:28:33 -04:00
|
|
|
--output json |
|
|
|
|
yq eval '.Reservations[].Instances[].InstanceId' -
|
2022-11-08 10:43:17 -05:00
|
|
|
)
|
2022-11-10 08:17:04 -05:00
|
|
|
workerInstances=$(
|
2023-07-13 10:28:33 -04:00
|
|
|
aws ec2 describe-instances \
|
|
|
|
--filters "Name=tag:constellation-uid,Values=${2}" "Name=tag:constellation-role,Values=worker" \
|
2022-11-10 08:17:04 -05:00
|
|
|
--region "${1}" \
|
|
|
|
--no-paginate \
|
2023-07-13 10:28:33 -04:00
|
|
|
--output json |
|
|
|
|
yq eval '.Reservations[].Instances[].InstanceId' -
|
2022-11-08 10:43:17 -05:00
|
|
|
)
|
|
|
|
|
2023-07-13 10:28:33 -04:00
|
|
|
echo "Fetching logs from control planes"
|
2022-11-08 10:43:17 -05:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
for instance in ${controlInstances}; do
|
2022-11-10 08:17:04 -05:00
|
|
|
printf "Fetching for %s\n" "${instance}"
|
|
|
|
aws ec2 get-console-output --region "${1}" --instance-id "${instance}" |
|
|
|
|
jq -r .'Output' |
|
|
|
|
tail -n +2 > control-plane-"${instance}".log
|
2022-11-08 10:43:17 -05:00
|
|
|
done
|
|
|
|
|
2023-07-13 10:28:33 -04:00
|
|
|
echo "Fetching logs from worker nodes"
|
2022-11-08 10:43:17 -05:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
for instance in ${workerInstances}; do
|
2022-11-10 08:17:04 -05:00
|
|
|
printf "Fetching for %s\n" "${instance}"
|
|
|
|
aws ec2 get-console-output --region "${1}" --instance-id "${instance}" |
|
|
|
|
jq -r .'Output' |
|
|
|
|
tail -n +2 > worker-"${instance}".log
|
2022-11-08 10:43:17 -05:00
|
|
|
done
|