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}"
|
|
|
|
|
|
|
|
pushd constellation-terraform
|
2022-11-10 08:17:04 -05:00
|
|
|
controlAutoscalingGroup=$(
|
|
|
|
terraform show -json |
|
2022-11-08 10:43:17 -05:00
|
|
|
jq -r .'values.root_module.child_modules[] |
|
|
|
|
select(.address == "module.instance_group_control_plane") |
|
2022-11-10 08:17:04 -05:00
|
|
|
.resources[0].values.name'
|
2022-11-08 10:43:17 -05:00
|
|
|
)
|
2022-11-10 08:17:04 -05:00
|
|
|
workerAutoscalingGroup=$(
|
|
|
|
terraform show -json |
|
2022-11-08 10:43:17 -05:00
|
|
|
jq -r .'values.root_module.child_modules[] |
|
|
|
|
select(.address == "module.instance_group_worker_nodes") |
|
2022-11-10 08:17:04 -05:00
|
|
|
.resources[0].values.name'
|
2022-11-08 10:43:17 -05:00
|
|
|
)
|
2022-12-08 10:55:56 -05:00
|
|
|
popd
|
2022-11-08 10:43:17 -05:00
|
|
|
|
2022-11-10 08:17:04 -05:00
|
|
|
controlInstances=$(
|
|
|
|
aws autoscaling describe-auto-scaling-groups \
|
|
|
|
--region "${1}" \
|
|
|
|
--no-paginate \
|
|
|
|
--output json \
|
|
|
|
--auto-scaling-group-names "${controlAutoscalingGroup}" |
|
|
|
|
jq -r '.AutoScalingGroups[0].Instances[].InstanceId'
|
2022-11-08 10:43:17 -05:00
|
|
|
)
|
2022-11-10 08:17:04 -05:00
|
|
|
workerInstances=$(
|
|
|
|
aws autoscaling describe-auto-scaling-groups \
|
|
|
|
--region "${1}" \
|
|
|
|
--no-paginate \
|
|
|
|
--output json \
|
|
|
|
--auto-scaling-group-names "${workerAutoscalingGroup}" |
|
|
|
|
jq -r '.AutoScalingGroups[0].Instances[].InstanceId'
|
2022-11-08 10:43:17 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
echo "Fetching logs from control planes: ${controlInstances}"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
echo "Fetching logs from worker nodes: ${workerInstances}"
|
|
|
|
|
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
|