Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try another container if starting an rds shell fails #143

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions bin/rds/shell
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ echo "Engine: $RDS_ENGINE"
echo "Root username: $RDS_ROOT_USERNAME"
echo "VPC ID: $RDS_VPC"

CHOOSE_NTH_INSTANCE=0
if [ -z "$ECS_INSTANCE_ID" ]
then
echo "==> Finding ECS instance..."
Expand All @@ -106,15 +107,22 @@ then
)
ECS_INSTANCE_ID=$(
echo "$ECS_INSTANCES" \
| jq -r .Reservations[0].Instances[0].InstanceId
| jq -r .Reservations[0].Instances[$CHOOSE_NTH_INSTANCE].InstanceId
)
fi

echo "ECS instance ID: $ECS_INSTANCE_ID"

echo "==> Starting $RDS_ENGINE session on $RDS_IDENTIFIER..."

aws ssm start-session \
while ! aws ssm start-session \
--target "$ECS_INSTANCE_ID" \
--document-name "$RDS_IDENTIFIER-rds-shell" \
--parameters "RootPassword=$RDS_ROOT_PASSWORD"
--parameters "RootPassword=$RDS_ROOT_PASSWORD";
do
((CHOOSE_NTH_INSTANCE=CHOOSE_NTH_INSTANCE+1))
ECS_INSTANCE_ID=$(
echo "$ECS_INSTANCES" \
| jq -r .Reservations[0].Instances[$CHOOSE_NTH_INSTANCE].InstanceId
)
done