Skip to content

Instantly share code, notes, and snippets.

@karthikeayan
Created December 12, 2021 15:06
Show Gist options
  • Save karthikeayan/047d1f7aa556da265fd389e56985e7fc to your computer and use it in GitHub Desktop.
Save karthikeayan/047d1f7aa556da265fd389e56985e7fc to your computer and use it in GitHub Desktop.
Get shell of a container running on as a ECS Task
#!/usr/local/bin/bash
echo Enter Cluster Name:
read -e cluster_name
echo Enter Container Name:
read -e container_name
echo Enter Service Name:
read -e service_name
echo Enter AWS Profile Name:
read -e profile
region="eu-west-1"
task_ids=($(aws ecs list-tasks --cluster ${cluster_name} --service-name ${service_name} --profile ${profile} --region ${region} | jq '.taskArns[]' -r | cut -d'/' -f3))
counter=1
declare -A tasks
for i in "${task_ids[@]}"
do
echo "${counter}: ${i}"
tasks["${counter}"]="${i}"
counter=$((counter+1))
done
echo Enter Task Number:
read task_counter
aws ecs execute-command --cluster ${cluster_name} --task ${tasks["${task_counter}"]} --container ${container_name} --interactive --command "/bin/sh" --profile ${profile} --region ${region}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment