Skip to content

Commit 9cd6f8c

Browse files
authored
Login to aws if required for shell access (#3577)
Try to login with `aws sso login` if necessary when shelling out to nodes.
2 parents 3aa36c1 + ce50076 commit 9cd6f8c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

script/shell.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ while [[ $# -gt 0 ]]; do
4040
task_ip="$2"
4141
shift 2
4242
;;
43+
--exit-without-login|-x)
44+
exit_without_login=true
45+
shift
46+
;;
4347
-h|--help)
4448
usage
4549
exit 0
@@ -64,6 +68,20 @@ fi
6468

6569
cluster_name="mavis-$env"
6670

71+
aws sts get-caller-identity &>/dev/null
72+
if [[ $? -ne 0 ]]; then
73+
if [[ -z "$exit_without_login" ]]; then
74+
aws sso login
75+
if [[ $? -ne 0 ]]; then
76+
echo "Error: AWS CLI SSO login failed. Please log in to your AWS account."
77+
exit 1
78+
fi
79+
else
80+
echo "Error: AWS SSO login required. Please log in to your AWS account using 'aws sso login'."
81+
exit 1
82+
fi
83+
fi
84+
6785
if [ -n "$task_id" ]; then
6886
task_description=$(aws ecs describe-tasks --region "$region" --cluster "$cluster_name" --task "$task_id")
6987
if [ -z "$task_description" ] || echo "$task_description" | jq -e '.tasks | length == 0' > /dev/null; then

0 commit comments

Comments
 (0)