Skip to main content

Interactive shell for AWS ECS tasks with service and task selection.

Project description

ecs-shell

PyPI version ecs-shell

ecs-shell is yet another interactive CLI tool for connecting to AWS ECS (Elastic Container Service) tasks. It provides a user-friendly interface to browse services, select tasks, and establish shell sessions - all without having to remember complex AWS CLI commands or task IDs.

I have created this as an utility for me in the past, and only later found that there are plenty of others out there. I think the CLI UX with this one is better, so I decided to publish it anyways.

https://github.com/user-attachments/assets/065ad13e-38fc-4e71-a9bc-d57973d347f7

โœจ Features

  • ๐ŸŽฏ Interactive Selection: Browse and select ECS services and tasks using arrow keys
  • ๐ŸŽจ Rich UI: Beautiful terminal interface with color-coded output
  • โšก Fast Navigation: Quickly filter through services and tasks
  • ๐Ÿ“Š Task Details: View task creation time, CPU/Memory allocation, and container information
  • ๐Ÿ”„ Session Management: Seamless shell session establishment with AWS ECS Exec
  • ๐Ÿ” Profile Support: Use any AWS CLI profile for multi-account workflows

๐Ÿ“‹ Requirements

Before using ecs-shell, ensure you have the following installed and configured:

1. AWS CLI

The AWS CLI must be installed and authenticated with appropriate permissions.

# Install AWS CLI (macOS)
brew install awscli

# Configure your AWS credentials
aws configure

Required AWS Permissions:

  • ecs:ListServices
  • ecs:ListTasks
  • ecs:DescribeTasks
  • ecs:ExecuteCommand

2. Session Manager Plugin

The Session Manager plugin is required for establishing interactive sessions with ECS tasks.

# Install Session Manager plugin (macOS)
brew install --cask session-manager-plugin

# Verify installation
session-manager-plugin --version

For other operating systems, see the AWS Session Manager Plugin installation guide.

3. Python

Python 3.10 or higher is required.

# Check your Python version
python3 --version

4. ECS Task Configuration

Your ECS tasks must have ECS Exec enabled. This is configured in your task definition:

{
  "enableExecuteCommand": true
}

๐Ÿš€ Installation

Using pipx (Recommended)

pipx installs CLI tools in isolated environments, avoiding conflicts:

# Install pipx if you haven't already
brew install pipx
pipx ensurepath

# Install ecs-shell
pipx install ecs-shell

Using pip

# Install globally
pip install ecs-shell

# Or in a virtual environment
python3 -m venv venv
source venv/bin/activate
pip install ecs-shell

Upgrade

# With pipx
pipx upgrade ecs-shell

# With pip
pip install --upgrade ecs-shell

๐Ÿ“– Usage

Basic Usage

ecs-shell <profile> <cluster>

Arguments:

  • profile: AWS CLI profile name (from ~/.aws/credentials)
  • cluster: ECS cluster name

Examples

# Connect to staging cluster using 'production' profile
ecs-shell production my-cluster-staging

# Connect to development cluster
ecs-shell dev-profile dev-cluster

# Use default profile
ecs-shell default my-cluster

Interactive Flow

  1. Select a Service: Browse through all services in your cluster
  2. Select a Task: Choose from running tasks in the selected service
  3. Connect: Automatically establishes a shell session to the task
๐Ÿš€ ECS Interactive Shell
Profile: production | Cluster: my-cluster-staging

? Select a service: 
โฏ api-service
  worker-service
  frontend-service
  
? Select a task:
โฏ abc123def456 | 2024-11-05 10:30:15 | api-container
  xyz789ghi012 | 2024-11-05 09:15:42 | api-container

โ•ญโ”€ Connecting to ECS Task โ”€โ•ฎ
โ”‚ Profile: production       โ”‚
โ”‚ Cluster: my-cluster       โ”‚
โ”‚ Task: abc123def456        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Starting session with SessionId: ecs-execute-command-...
sh-4.2$

Navigation

  • โ†‘/โ†“ Arrow Keys: Navigate through options
  • Enter: Select the highlighted option
  • Ctrl+C: Cancel and exit

๐Ÿ› ๏ธ Development

Setup

# Clone the repository
git clone https://github.com/yourusername/ecs-shell.git
cd ecs-shell

# Create and activate virtual environment
make setup-venv
source venv/bin/activate

# Install dependencies
make install-deps

# Install ecs-shell in development mode
make local-install

Commands

make help           # Show all available commands
make lint           # Run linting checks
make format         # Auto-format code
make local-install  # Install package locally (in active environment)

Code Quality

This project uses:

  • ruff: Fast Python linter and formatter
  • pyright: Static type checker

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ› Troubleshooting

"ExecuteCommandException: Task must have 'enableExecuteCommand' enabled"

Your ECS tasks need to have ECS Exec enabled. Update your task definition:

{
  "enableExecuteCommand": true
}

After updating, you'll need to deploy new tasks for the change to take effect.

"Session Manager plugin not found"

Install the Session Manager plugin:

brew install --cask session-manager-plugin

"Access Denied" errors

Ensure your IAM user/role has the required permissions:

  • ecs:ExecuteCommand
  • ecs:ListServices
  • ecs:ListTasks
  • ecs:DescribeTasks

No services or tasks found

  • Verify the cluster name is correct
  • Ensure you're using the right AWS profile
  • Check that services are running in the cluster

๐Ÿ”— Related Resources

โญ Acknowledgments

Built with:

  • boto3 - AWS SDK for Python
  • inquirer - Interactive command line prompts
  • rich - Beautiful terminal formatting

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecs_shell-0.0.1.dev6.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ecs_shell-0.0.1.dev6-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file ecs_shell-0.0.1.dev6.tar.gz.

File metadata

  • Download URL: ecs_shell-0.0.1.dev6.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for ecs_shell-0.0.1.dev6.tar.gz
Algorithm Hash digest
SHA256 5a441bddc6d1ef3a9f2ec1efea80edb174c0c2ed7231bf8639feb7b5ccca4f75
MD5 d68480b96f3838e9bc0df873be12f250
BLAKE2b-256 b431beb3c4d4e2dc6fa02afaff5cb9b98fefebf4760f1c0f462059d09f8a33dd

See more details on using hashes here.

File details

Details for the file ecs_shell-0.0.1.dev6-py3-none-any.whl.

File metadata

  • Download URL: ecs_shell-0.0.1.dev6-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for ecs_shell-0.0.1.dev6-py3-none-any.whl
Algorithm Hash digest
SHA256 837c39ef3d86b5a0f673371d2ab869a7267aadd522a685ce031b5063e8761561
MD5 34ae5621c976d83b180dad66b7d13b80
BLAKE2b-256 b2c0eaca45e157af70d12de7bde74ee857daf6e6af84b195b5da4a680c0a9e3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page