Skip to content

Instantly share code, notes, and snippets.

@qoomon
Last active February 1, 2022 07:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoomon/03065cadecc4df60a7eaeac811e794fd to your computer and use it in GitHub Desktop.
Save qoomon/03065cadecc4df60a7eaeac811e794fd to your computer and use it in GitHub Desktop.
Connect into AWS ECS Container
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