Last active
February 1, 2022 07:50
-
-
Save qoomon/03065cadecc4df60a7eaeac811e794fd to your computer and use it in GitHub Desktop.
Connect into AWS ECS Container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLUSTER_NAME=$1 | |
SERVICE_NAME=$2 | |
CONTAINER_NAME=$3 | |
COMMAND=${4:-'/bin/sh'} | |
# get first running task | |
TASK_ID=$(aws ecs list-tasks \ | |
--cluster $CLUSTER_NAME \ | |
--service-name $SERVICE_NAME \ | |
--desired-status RUNNING \ | |
--query 'taskArns[0]' \ | |
--output text \ | |
| sed 's|.*/||') | |
if [ -z "$TASK_ID" ] | |
then | |
echo 'Could not find any running tasks' | |
exit 1 | |
fi | |
echo TASK_ID=$TASK_ID | |
aws ecs execute-command \ | |
--cluster $CLUSTER_NAME \ | |
--task $TASK_ID \ | |
--container $CONTAINER_NAME \ | |
--command "$COMMAND" \ | |
--interactive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment