Skip to main content

Wrapping some awscli commands with beautiful TUI

Project description

[!WARNING] There is no "stable" version published on pypip yet. This tool is under development.

logo

cloudsnake 🐍

Wrapping some awscli commands with beautiful TUI

Build with ❤ in Python

Table of Contents generated with DocToc

example

Why cloudsnake

The main intention of this tool is to continue improving my python skills, get to know the AWS boto3 SDK better, and learn how to create a CLI using typer, rich, and textual. The tool tries to implement some commands from the official AWS cli (aws cli), adding my own logic and with highlights (pretty print json output/table with typer/rich).

[!IMPORTANT] Do not try to use part of this code in a productive app as it is currently untested. (visit #TO DO section). I also don't know if this is the best way to use any of the tools that the application uses (boto3, typer, rich...), that is why any PR is welcome, it will be appreciated so I can continue improving my skills.

[!IMPORTANT] In the end, the purpose of this tool is also to be able to facilitate the day to day, creating tools that help me to operate the platform. For example, to quickly connect to EC2, RDS...etc.

Badges

Code Code Size
CI/CD CI - Test CD - Build
Package pythonPyPI - Version packaging
Meta pre-commit License - MIT
Linter Ruff

Available implementations

  • Connect to EC2 instances using SSM. You can pass the instance id (--target) or use the interactive menu (--with-instance-selector)

  • Connect to the RDS instances using IAM db authentication.

See examples in the next section

Examples

For the examples, you need to be authenticated to AWS account using your local credentials.

In your terminal, set the corresponding AWS_PROFILE=MyProfile if not using the default. (~/.aws/credentials)

Connect to the EC2 instance using SSM

cloudsnake ssm start-session --with-instance-selector # will print all your instances in a terminal menu
cloudsnake ssm start-session --target i-XXXXXX  # connect to the instance specifying the target id

Example

example_ssm_connect

Connect to the RDS instance using IAM authentication db token

Please follow this instructions to setup your RDS IAM authentication.

Download the cert

By default, cloudsnake forces to use TLS/SSL connections.

cloudsnake rds download-cert --save-path /tmp

Other region:

cloudsnake --region us-east-1 download-cert --save-path /tmp

Connect to the instance

Example for the region eu-west-1:

cloudsnake rds connect -h XXXXX.XXXXXX.eu-west-1.rds.amazonaws.com -u ADMIN --cert /tmp/rds-cert-eu-west-1.pem

Example

example_rds

Installation

Using pip

pip3 install cloudsnake

[!WARNING] Probably your system will not allow this installation method due to a broken system package.

Example error
Error:

error: externally-managed-environment

× This environment is externally managed ╰─> To install Python packages system-wide, try 'pacman -S python-xyz', where xyz is the package you are trying to install.

If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.

If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. Make sure you have python-pipx
installed via pacman.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.

Using pipx with virtualenv (recommended)

Install pipx with your system package manager (apt, dnf, pacman...).

pipx install cloudsnake

Local install

git clone https://github.com/containerscrew/cloudsnake.git
cd cloudsnake
make pipx-local-install

Uninstall

Using pip

pip3 uninstall cloudsnake

Using pipx

pipx uninstall cloudsnake

Local development

Local run with poetry

git clone https://github.com/containerscrew/cloudsnake.git
cd cloudsnake
make update
make run

Run & install pre-commit

make pre-commit-install
make run-pre-commit

Testing

git clone https://github.com/containerscrew/cloudsnake.git
cd cloudsnake
make run-tests

TO DO

  • Documentation with docstrings
  • Add more tests with pytest and boto3 mock
  • Remove @classmethod
  • Ruff linter
  • Cliff: changelog
  • Pipelines with github actions. Automatic publish new version to pypip
  • Other...

Improvements

Positional flags

Actually

cloudsnake --log-level debug --region us-east-1 --profile default ec2 describe-instance

Wants

cloudsnake ec2 describe-instances --log-level debug --region us-east-1 --profile default --other-specific-flags-for-this-subdommand

TOP LINKS

links.md

Poetry commands

poetry.md

Cloudsnake commands

cloudsnake --help
cloudsnake ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query 'Reservations[*].Instances[*].{Instance:InstanceId,VpcId:VpcId,AZ:Placement.AvailabilityZone,Name:Tags[?Key==`Name`]|[0].Value}' --output json
cloudsnake ec2 describe-instances --filters "Name=instance-state-name,Values=running" --output json
cloudsnake ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query 'Reservations[*].Instances[*].{InstanceName:Tags[?Key==`Name`]|[0].Value}' --output json
cloudsnake ec2 describe-instances  --filters "Name=instance-state-name,Values=running" --query 'Reservations[*].Instances[*].Tags[?Key==`Name`].Value[][]'
cloudsnake rds describe-db-instances --query 'DBInstances[*].DBInstanceIdentifier'
cloudsnake ssm start-session --with-instance-selector
cloudsnake ssm start-session --target i-xxxxxxx

License

cloudsnake is distributed under the terms of the MIT license.

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

cloudsnake-0.4.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

cloudsnake-0.4.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file cloudsnake-0.4.0.tar.gz.

File metadata

  • Download URL: cloudsnake-0.4.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.6-arch1-1

File hashes

Hashes for cloudsnake-0.4.0.tar.gz
Algorithm Hash digest
SHA256 568786e285334da8e0999d90df0fde8cb1c0657e293c8db0d6255b5dad0eec5c
MD5 8cfb5b21c09cc0d4bcae205957b533ed
BLAKE2b-256 d380c08282f19df6676aa1319060b780cee82407a7c1493207a01a2064bf88f9

See more details on using hashes here.

File details

Details for the file cloudsnake-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: cloudsnake-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.6-arch1-1

File hashes

Hashes for cloudsnake-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a2ce16a3caa308426552004eab291cf5962af61a5afdc3c3e37e895f33919f7
MD5 a4733c9014023b748bba3b70377fccee
BLAKE2b-256 ca7ce60c30e590232afb4b69cab407b0ead7612f55a29c691c29ff6be1519fb6

See more details on using hashes here.

Supported by

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