Skip to main content

A CLI tool to manage and connect to AWS EC2 instances

Project description

# EC2 Simple connect

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/)

A powerful CLI tool for managing and connecting to AWS EC2 instances with automatic security group management and configuration handling.

## Features

- 🚀 Easy connection to EC2 instances
- 🔒 Automatic security group management
- ⚙️ Persistent configuration management
- 🌍 Region selection and management
- 💻 Instance state handling (start/stop)
- 🔑 SSH key management
- 🛡️ Secure credential handling
- 📝 Comprehensive logging

## Installation

```bash
pip install ec2-simple-connect

Prerequisites

  1. Python 3.7 or higher
  2. AWS Account and credentials
  3. SSH key pairs for your EC2 instances

Quick Start

  1. Configure your AWS credentials:
aws configure
  1. Run EC2 Manager:
ec2-simple-connect

On first run, the tool will guide you through configuration setup.

Configuration

The tool creates a configuration file at ~/.ec2manager/config.ini with the following settings:

[DEFAULT]
ssh_key_path = ~/.ssh
default_region = us-east-1
default_username = ec2-user
security_group_protocol = tcp
security_group_port = 22

Configuration Options

Option Description Default
ssh_key_path Path to SSH keys directory ~/.ssh
default_region Default AWS region us-east-1
default_username Default SSH username ec2-user
security_group_protocol Security group protocol tcp
security_group_port Security group port 22

Usage

Basic Usage

  1. Start the tool:
ec2-manager
  1. Select a region from the displayed list

  2. Choose an instance to connect to

  3. Enter username (or press Enter for default)

Features in Detail

Region Selection

  • Lists all available AWS regions
  • Remembers last used region
  • Easy switching between regions

Instance Management

  • Lists all instances with details:
    • Instance ID
    • Name
    • Status
    • Public IP
  • Supports starting stopped instances
  • Handles instance state transitions

Security Group Management

  • Automatically manages security group rules
  • Adds rules for your current IP
  • Removes rules when disconnecting
  • Supports custom protocols and ports

SSH Connection

  • Automatic SSH key selection
  • Custom username support
  • Handles different instance states
  • Secure connection settings

Security

  • Configurations stored in protected directory (~/.ec2manager)
  • Secure file permissions (600 for config files)
  • Temporary security group rules
  • No storage of sensitive credentials

Development

Setting Up Development Environment

  1. Clone the repository:
git clone https://github.com/yourusername/ec2-manager.git
cd ec2-manager
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install development dependencies:
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

# Format code
black src tests

# Sort imports
isort src tests

# Check style
flake8 src tests

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Common Issues and Solutions

Issue: "Unable to locate credentials"

  • Ensure AWS credentials are configured: aws configure
  • Check ~/.aws/credentials exists and has valid credentials

Issue: "Permission denied (publickey)"

  • Verify SSH key exists in configured path
  • Check key permissions (should be 600)
  • Confirm correct username for instance

Issue: "Connection timed out"

  • Verify security group rules
  • Check instance public IP is accessible
  • Ensure instance is running

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • AWS SDK for Python (Boto3)
  • The AWS CLI team for inspiration
  • All contributors and users

Support

If you encounter any issues or need support, please:

  1. Check the Common Issues section
  2. Search existing GitHub issues
  3. Create a new issue if needed

Project Status

Active development - Accepting contributions

Author

Meraj (meru.meraj64@gmail.com)


Made with ❤️ by meraj64

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

ec2_simple_connect-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ec2_simple_connect-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file ec2_simple_connect-0.1.0.tar.gz.

File metadata

  • Download URL: ec2_simple_connect-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for ec2_simple_connect-0.1.0.tar.gz
Algorithm Hash digest
SHA256 464c26ac74132480d906d5ae99d1cfe2d4318c3f733d9971f64f5d9f912f0e0f
MD5 684ea725a6198ff8b5f04eb55370d83b
BLAKE2b-256 e3d458f44884447fa852a96ad3a05e7ee8b4ded5b661da654cd95a2241ac05fa

See more details on using hashes here.

File details

Details for the file ec2_simple_connect-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ec2_simple_connect-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 199df5f7b6dab23dfa1f20138ad74941a04dfa32257989cd1a8f8688eb64822f
MD5 484d4e91cf24a0b620a7b50902bbe95e
BLAKE2b-256 cd30f74301da9a5984a4cd685779928c0ca4cd17848346b982a0e0fe5734f96f

See more details on using hashes here.

Supported by

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