Skip to content

Instantly share code, notes, and snippets.

@ship-happens
Last active December 20, 2025 00:10
Show Gist options
  • Select an option

  • Save ship-happens/df690fe2d102a52ed8fbbe447b9aab36 to your computer and use it in GitHub Desktop.

Select an option

Save ship-happens/df690fe2d102a52ed8fbbe447b9aab36 to your computer and use it in GitHub Desktop.
ECS SSH
#!/bin/bash
CLUSTER=$1
SERVICE=$2
CONTAINER=$3
shift 3
AWS_ARGS=$@
LIST=`aws ecs list-tasks --cluster $CLUSTER --service $SERVICE $AWS_ARGS`
if [ "$?" -ne "0" ]; then
exit 1
fi
ARNS=($(ruby -rjson -e "puts JSON.parse('${LIST}')['taskArns']"))
i=0
for ARN in ${ARNS[@]}; do
i=$((i+1))
echo "$i) ${ARN}"
done
echo -n "Enter a number from 1 (default) to $i to select a task: "
read -r ARN_NUM
ARN_NUM=${ARN_NUM:-1}
TASK=${ARNS[ARN_NUM - 1]}
aws ecs execute-command --cluster $CLUSTER --task $TASK --container $CONTAINER --interactive --command bash $AWS_ARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment