Interactive shell for AWS ECS tasks with service and task selection.
Project description
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:ListServicesecs:ListTasksecs:DescribeTasksecs: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
- Select a Service: Browse through all services in your cluster
- Select a Task: Choose from running tasks in the selected service
- 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:
๐ค 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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:ExecuteCommandecs:ListServicesecs:ListTasksecs: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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a441bddc6d1ef3a9f2ec1efea80edb174c0c2ed7231bf8639feb7b5ccca4f75
|
|
| MD5 |
d68480b96f3838e9bc0df873be12f250
|
|
| BLAKE2b-256 |
b431beb3c4d4e2dc6fa02afaff5cb9b98fefebf4760f1c0f462059d09f8a33dd
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
837c39ef3d86b5a0f673371d2ab869a7267aadd522a685ce031b5063e8761561
|
|
| MD5 |
34ae5621c976d83b180dad66b7d13b80
|
|
| BLAKE2b-256 |
b2c0eaca45e157af70d12de7bde74ee857daf6e6af84b195b5da4a680c0a9e3b
|