Sha256: 6f2aa2a3af86d22468e3095d5e90def2c8a9225eaf54f0e4c62525ef111a803b

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

#!/usr/bin/env bash

CLUSTER_NAME="CLUSTER_NAME"
SERVICE_NAME="SERVICE_NAME"
REGION="AWS_REGION"

# Validate input
if [ -z "$1" ]; then
  echo "Usage: $0 <command>"
  echo "Example: $0 /bin/bash"
  exit 1
fi

# Command to run inside the container
COMMAND="$1"

# Step 1: Get the first task ARN
TASK_ARN=$(aws ecs list-tasks \
  --cluster "$CLUSTER_NAME" \
  --service-name "$SERVICE_NAME" \
  --region "$REGION" \
  --query "taskArns[0]" \
  --output text)

if [ "$TASK_ARN" == "None" ]; then
  echo "No running tasks found for service $SERVICE_NAME in cluster $CLUSTER_NAME."
  exit 1
fi

# Step 2: Get container names in the task
CONTAINER_NAMES=$(aws ecs describe-tasks \
  --cluster "$CLUSTER_NAME" \
  --tasks "$TASK_ARN" \
  --region "$REGION" \
  --query "tasks[0].containers[].name" \
  --output text)

# Check if containers exist
if [ -z "$CONTAINER_NAMES" ]; then
  echo "No containers found in the task $TASK_ARN."
  exit 1
fi

# Step 3: Display container options and prompt user to choose
echo "Containers available in the task:"
select CONTAINER_NAME in $CONTAINER_NAMES; do
  if [ -n "$CONTAINER_NAME" ]; then
    echo "You selected container: $CONTAINER_NAME"
    break
  else
    echo "Invalid selection. Please choose a valid container."
  fi
done

# Step 4: Attach to the selected container and run the custom command
echo "Attaching to container '$CONTAINER_NAME' in task '$TASK_ARN' and running command: $COMMAND..."
aws ecs execute-command \
  --cluster "$CLUSTER_NAME" \
  --task "$TASK_ARN" \
  --container "$CONTAINER_NAME" \
  --command "$COMMAND" \
  --interactive

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
easy_ml-0.2.0.pre.rc52 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc51 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc50 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc49 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc48 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc47 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc46 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc45 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc44 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc43 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc41 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc40 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc39 bin/ecs/exec_command.sh
easy_ml-0.2.0.pre.rc38 bin/ecs/exec_command.sh