Welcome to the ECS Exec CLI project! This tool is designed to interactively execute commands within an AWS ECS
container using the ecs execute-command functionality. It was developed as a learning project to explore Rust.
Note: This project is tailored to a specific workflow and setup, but it can be adapted and extended by other developers.
- Asynchronous Rust: Powered by the Tokio runtime for handling concurrent tasks.
- AWS SDK Integration: Uses AWS SDK for Rust to interact with ECS clusters and tasks.
- Custom Cluster Suffix Matching: Specifically looks for ECS clusters ending with
-main. - Execute Commands in ECS Containers: Provides functionality to run any command within a specific ECS container.
Before using this tool, ensure you have the following set up:
- Rust: Install Rust by following the official Rust installation guide.
- AWS CLI: Ensure you have the AWS CLI installed and configured with proper permissions.
- You can install the AWS CLI here.
- AWS Permissions: The IAM role associated with your AWS CLI profile should have permissions for
ecs:DescribeClusters,ecs:ListTasks,ecs:ExecuteCommand, and other related actions.
-
Clone the repository:
git clone https://github.com/yourusername/ecs-exec-cli.git
-
Navigate to the project directory:
cd ecs-exec-cli -
Build the project:
cargo build --release- Run the executable:
./target/release/ecs-exec-cli --helpThis CLI tool supports both named and positional arguments. You can specify the ECS cluster, task, and command either with flags or positionally.
./ecs-exec-cli --profile <AWS_PROFILE> --region <AWS_REGION> <SERVICE> <CONTAINER> <COMMAND>./ecs-exec-cli --profile my-aws-profile --region us-east-1 my-service-name my-container-name "/bin/bash"- Connect to the specified ECS cluster and task.
- Open an interactive shell (/bin/bash) within the container.
- --profile (-p): The AWS CLI profile to use (defaults to dt-infra).
- --region (-r): The AWS region to use (defaults to eu-north-1).
- : The name of the ECS service (positional).
- : The ECS container name (positional).
- : The command to execute inside the container (positional).
- The project currently looks for ECS clusters that end with -main. This is a specific setup related to the personal workflow of the author. Feel free to modify this to suit your needs.
- It also defaults to using app as the container name, which is configurable with the --container flag.
Since this project was built as part of a Rust learning journey, contributions are more than welcome! Whether you’re learning Rust or want to help improve the tool, feel free to:
- Fork the repository.
- Create a new branch (git checkout -b feature/my-new-feature).
- Commit your changes (git commit -am 'Add some feature').
- Push to the branch (git push origin feature/my-new-feature).
- Open a pull request.
- Support for more flexible ECS cluster matching (not tied to -main).
- Error handling improvements.
- More robust interaction with AWS services.
- Adding unit and integration tests.
This project is licensed under the MIT License. See the LICENSE file for details.
Thanks to the Rust and AWS SDK communities for providing excellent documentation and resources to get started!