Last active
April 15, 2025 05:45
-
-
Save tkhk/e374b3c6760f25091ce7b87190159ca0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
set -euo pipefail | |
select_option() { | |
local prompt_message=$1 | |
shift | |
local options=("$@") | |
PS3="$prompt_message" | |
select opt in "${options[@]}"; do | |
if [[ -n "$opt" ]]; then | |
echo "$opt" | |
break | |
else | |
echo "Invalid selection. Please try again." | |
fi | |
done | |
} | |
clusters=$(aws ecs list-clusters --query 'clusterArns[*]' --output text) | |
cluster_name=$(select_option "Select cluster: " $clusters) | |
tasks=$(aws ecs list-tasks --cluster $cluster_name --query 'taskArns[*]' --output text) | |
task_id=$(select_option "Select task: " $tasks) | |
containers=$(aws ecs describe-tasks --cluster $cluster_name --tasks $task_id --query 'tasks[*].containers[*].name' --output text) | |
container_name=$(select_option "Select container: " $containers) | |
if [[ -z "$task_id" || -z "$container_name" ]]; then | |
echo "Error: task and container must be provided." | |
exit 1 | |
fi | |
aws ecs execute-command \ | |
--cluster $cluster_name \ | |
--task $task_id \ | |
--container $container_name \ | |
--interactive \ | |
--command "/bin/sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment