A production-grade, containerized tool to list AWS EC2 instances securely. Optimized for speed, security, and scalability.
- Security First: Runs as a non-privileged user. Supports IAM Roles, Instance Profiles, and Environment Variables.
- Scalable: Uses AWS SDK (
boto3) pagination to handle accounts with thousands of instances. - Machine Readable: Optional JSON output for easy integration with other automation tools.
- Lightweight: Multi-stage Alpine-based Docker build (~50MB image).
- Observability: Structured JSON logging and advanced health checks (verifies AWS connectivity).
- CI/CD Ready: Integrated GitHub Actions for automated testing and Docker validation.
- Docker (20.10+)
- AWS Credentials (IAM User or Role) with
ec2:DescribeInstancesandec2:DescribeRegionspermissions.
docker build -t docker-ec2-manager DockerEC2Manager/The tool supports both positional arguments and flags.
Standard Text Output:
docker run --rm \
-e AWS_ACCESS_KEY_ID=xxx \
-e AWS_SECRET_ACCESS_KEY=xxx \
docker-ec2-manager us-west-2JSON Output (Ideal for piping to jq):
docker run --rm \
-e AWS_ACCESS_KEY_ID=xxx \
-e AWS_SECRET_ACCESS_KEY=xxx \
docker-ec2-manager us-east-1 --jsonDebug Mode:
docker run --rm -e AWS_ACCESS_KEY_ID=xxx -e AWS_SECRET_ACCESS_KEY=xxx \
docker-ec2-manager us-east-1 --verbose| Flag | Description | Default |
|---|---|---|
region |
AWS Region to query | us-east-1 |
--json |
Output results in JSON format | False |
--verbose |
Enable DEBUG level logging | False |
# Install dependencies
pip install -r DockerEC2Manager/requirements-dev.txt
# Run Unit Tests
export PYTHONPATH=$PYTHONPATH:$(pwd)/DockerEC2Manager
pytest DockerEC2Manager/test_list_instances.py -vThis project uses GitHub Actions (.github/workflows/ci.yml) to:
- Run
pyteston every push. - Verify the multi-stage Docker build.
- Ensure 100% pass rate before deployment.
The container includes an advanced healthcheck.sh that verifies:
- Application script integrity.
- Python syntax.
- Optional: Connectivity to the AWS STS API (if credentials are provided).
Check health status with:
docker inspect --format='{{json .State.Health}}' <container_id>- Non-Root: The container runs as
appuser(UID 1000). - Slim Image: No
aws-clior shells are exposed in the final production image (onlyshfor healthchecks). - Credential Handling: Never hardcode keys. Use Docker secrets or environment variables.
MIT - Created by elliotsecops