A CLI tool to manage and connect to AWS EC2 instances
Project description
# EC2 Simple connect
[](https://opensource.org/licenses/MIT)
[](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
- Python 3.7 or higher
- AWS Account and credentials
- SSH key pairs for your EC2 instances
Quick Start
- Configure your AWS credentials:
aws configure
- 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
- Start the tool:
ec2-manager
-
Select a region from the displayed list
-
Choose an instance to connect to
-
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
- Clone the repository:
git clone https://github.com/yourusername/ec2-manager.git
cd ec2-manager
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Common Issues and Solutions
Issue: "Unable to locate credentials"
- Ensure AWS credentials are configured:
aws configure - Check
~/.aws/credentialsexists 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:
- Check the Common Issues section
- Search existing GitHub issues
- Create a new issue if needed
Project Status
Active development - Accepting contributions
Author
Meraj (meru.meraj64@gmail.com)
Made with ❤️ by meraj64
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
464c26ac74132480d906d5ae99d1cfe2d4318c3f733d9971f64f5d9f912f0e0f
|
|
| MD5 |
684ea725a6198ff8b5f04eb55370d83b
|
|
| BLAKE2b-256 |
e3d458f44884447fa852a96ad3a05e7ee8b4ded5b661da654cd95a2241ac05fa
|
File details
Details for the file ec2_simple_connect-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ec2_simple_connect-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
199df5f7b6dab23dfa1f20138ad74941a04dfa32257989cd1a8f8688eb64822f
|
|
| MD5 |
484d4e91cf24a0b620a7b50902bbe95e
|
|
| BLAKE2b-256 |
cd30f74301da9a5984a4cd685779928c0ca4cd17848346b982a0e0fe5734f96f
|