Skip to content

Instantly share code, notes, and snippets.

@ipmb ipmb/
Last active Nov 9, 2019

What would you like to do?
docker exec on AWS ECS with SSM
# USAGE: CLUSTER=mycluster SERVICE=myservice ./
set -euf -o pipefail
TASK_ARN=$(aws ecs list-tasks --cluster=$CLUSTER --service=$SERVICE \
| jq -r .taskArns[0])
if [ "$TASK_ARN" = "null" ]; then
echo "Could not find any running tasks for $SERVICE on cluster:$CLUSTER."
exit 1
CONTAINER_INSTANCE=$(aws ecs describe-tasks --cluster=$CLUSTER --task=$TASK_ARN \
| jq -r .tasks[0].containerInstanceArn)
INSTANCE_ID=$(aws ecs describe-container-instances --cluster=$CLUSTER --container-instances=$CONTAINER_INSTANCE \
| jq -r .containerInstances[0].ec2InstanceId)
echo "Connecting the remote Docker host..."
echo "Run the following to open a shell in the container:"
bold=$(tput bold)
normal=$(tput sgr0)
echo $bold' sudo docker exec -it $(curl -s http://localhost:51678/v1/tasks?taskarn='$TASK_ARN' | jq -r .Containers[0].DockerId) bash'$normal
aws ssm start-session --target=$INSTANCE_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.