Skip to main content

ecs_connect_cli

AWS ECS Exec command cli tool is aimed to :

  • connect to your container instance running under ECS Fargate.
  • tail the log from cloudwatch logs (if you configure a logconfiguration in your task definition)
  • update secret value into secret manager

 

The aws ecs execute-command command is quite complicated to remember and the tool give you the ability to parse and retrieve:

  • your clusters
  • your services
  • your tasks
  • your container

To let you choose which one you want to connect into.

Enhancements 😎 You can now connect to ECS and tail your logs from an EC2 instance or AWS CloudShell without the need of aws cli and aws credentials file.

At start, you are asked what kind of credentials you want to use and which default region.

You can now also update your secret directly from the command line.

ecs-connect-cli update-secret your-secret-name

I also add the possibility to run directly with pipx

pipx run ecs-connect-cli --help

 

Installation

Requirements

  • Install awscli via [https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html] (not necessary if you are connected to an EC2 instance)

  • Install ssm tools via [https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html]

 

To install you have several options:

  • Install it globally with your pip:
pip install ecs-connect-cli
  • Install it into a virtualenv (after creating a virtualenv with the tool of your choice):
source .venv_3.11.0/bin/activate
pip install ecs-connect-cli
  • Run the cli directly with pipx
pipx run ecs-connect-cli --help

 

if it is the first time you connect to aws-cli, you have to get credentials key from your aws administrator.

 

Usage

If you use it with with pip, you can call the CLI as below or directly call it with pipx

ecs-connect-cli --help


Welcome in AWS ECS Exec command Cli !

                                                                                                                                                                                       
 Usage: ecs_connect_cli [OPTIONS] COMMAND [ARGS]...                                                                                                                                        
                                                                                                                                                                                       
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --version             -v        Show the application's version and exit.                                                                   │
│ --install-completion            Install completion for the current shell.                                                                  │
│ --show-completion               Show completion for the current shell, to copy it or customize the installation.                           │
│ --help                          Show this message and exit.                                                                                │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ connect                           Connect to an ECS Fargate container                                                                      │
│ exec-command                      Execute manage.py command with args                                                                      │
│ list-cluster                      List cluster into an AWS account                                                                         │
│ list-service                      List service(s) into a cluster                                                                           │
│ list-task                         List task(s) into a service into a cluster                                                               │
│ tail                              Tail logs of a selected  ECS container                                                                   │
| update-secret                     Update secret from secret manager                                                                        |
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

 

Testing

The project now contains two test layers:

  • unit tests (fast, mocked CLI/AWS boundaries)
  • integration tests (real boto3 calls against MiniStack)

Local setup

Use a Python version supported by this project (3.10 to 3.14).

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Run unit tests

pytest -m "not integration" -q

Run integration tests with MiniStack

Start MiniStack:

docker run --rm -p 4566:4566 ministackorg/ministack

Run integration tests in another terminal:

export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_DEFAULT_REGION=us-east-1
export ECS_CONNECT_AWS_ENDPOINT_URL=http://localhost:4566
pytest -m "integration" -q

You can also use AWS_ENDPOINT_URL instead of ECS_CONNECT_AWS_ENDPOINT_URL.

Run all tests

pytest -q

 

Thanks to Typer from @tiangolo

Thanks to @kraymer for echoprompt 😎

Metadata

Release files for ecs_connect_cli 1.20.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ecs_connect_cli 1.20.0
File Size Uploaded Provenance Actions
ecs_connect_cli-1.20.0.tar.gz 9.9 kB Without provenance Details for ecs_connect_cli-1.20.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ecs_connect_cli 1.20.0
File Interpreter ABI Platform Actions
ecs_connect_cli-1.20.0-py3-none-any.whl Python 3 none any Details for ecs_connect_cli-1.20.0-py3-none-any.whl

Total release size: 21.2 kB

Release files / ecs_connect_cli-1.20.0.tar.gz

Download URL ecs_connect_cli-1.20.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
019ab5a70af5619138457420cbd45467d2b4a3608e4b55e0072051955c26a18e
BLAKE2b-256 checksum
How to use checksums
957ee05167d17fa6da268c9c0a9fa9fb720eae49a648c16eea1cc72fca0f5ba0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.0 CPython/3.12.3 Linux/6.17.0-1010-azure

Release files / ecs_connect_cli-1.20.0-py3-none-any.whl

Download URL ecs_connect_cli-1.20.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0536e32bb9d31f8bc70198ca4a8b71691d34227f4627e74931e075eb485915cc
BLAKE2b-256 checksum
How to use checksums
f82f4e7c47dea6816548b0ff342fea51a655a2d8d2aad565b34707279d1420cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.0 CPython/3.12.3 Linux/6.17.0-1010-azure

Security for ecs_connect_cli 1.20.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page