GithubHelp home page GithubHelp logo

jungle's Introduction

jungle

PyPI version GitHub license Build Status codecov.io

Description

jungle makes AWS operations from terminal simpler and more intuitive.

Why created

awscli is by far the most comprehensive CLI tool manipulating various AWS services, and I really like its flexible options and up-to-date release cycle. However, day-to-day AWS operations from my terminal don't need that much flexibility and that many services. Rather, I wanted just small set of UNIX-like commands which are easy to use and remember.

Installation

pip install jungle

Usage

EC2

I would highly recommend to use ssh-agent to manage your ssh keys and pass phrases. If you ssh-add your keys, ssh-agent automatically select appropriate key when you try to login to a box. This makes it much easier to use jungle ec2 ssh, or ssh command in general, since you don't have to specify --key-file /path/to/key.pem for each EC2 instance.

Listing all EC2 instances (each attribute is separated by a tab)

jungle ec2 ls

Listing all EC2 instances in formatted output(each attribute is separated with space and is aligned)

jungle ec2 ls -l

Filtering EC2 instances by Name tag

jungle ec2 ls blog-web-server-01

Filtering EC2 instances by Name tag using wildcard

jungle ec2 ls '*web*'

Starting instance

jungle ec2 up -i i-xxxxxx

Stopping instance

jungle ec2 down -i i-xxxxxx

SSH login to instance specified by instance id

jungle ec2 ssh -i i-xxxxxx --key-file /path/to/key.pem --port 1234

SSH login to instance specified by Tag Name

jungle ec2 ssh -n blog-web-server-01 --key-file /path/to/key.pem

SSH login to instance specified by Tag Name with wildcard (you'll be prompted to choose which server to log in)

jungle ec2 ssh -n 'blog-web-server-*' --key-file /path/to/key.pem

SSH login to instance specified by Tag Name through gateway instance

jungle ec2 ssh -n blog-web-server-01 --key-file /path/to/key.pem -g i-xxxxxx

SSH login to instance specified by Tag Name using auto ssh key discovery

jungle ec2 ssh -n blog-web-server-01

SSH login to instance gateway instance, specifying username for each instance, while disabling known_hosts prompt.

jungle ec2 ssh -i i-xxxxxx -u ec2-user -k /path/to/key.pem -s "-o UserKnownHostsFile=/dev/null" -g i-xxxxxx -x core

--dry-run gives you ssh command and exits.

jungle ec2 ssh -n blog-web-server-01 -u ec2-user --dry-run
ssh xxx.xxx.xxx.xxx@ec2-user

-P/--profile-name specify AWS profile name.

jungle ec2 -P myprofile ssh -n blog-web-server-01 -u ec2-user

ELB

Listing all ELB instances

jungle elb ls

Listing a ELB instance

jungle elb ls production-blog-elb

Listing ELB attached EC2 instances

jungle elb ls -l production-blog-elb

EMR

jungle emr ls
jungle emr ssh -k /path/to/key.pem -i j-xxxxxxx
jungle emr rm -i j-xxxxxxx

AutoScaling

jungle asg ls

RDS

jungle rds ls

Autocompletion (currently only supports bash)

Execuging the following command prints bash autocompletion script. Copy and past or redirect to your favorite file (e.g. /etc/bash_completion.d/jungle, ~/.bashrc). This is a function of click, which internally used by jungle.

$ _JUNGLE_COMPLETE=source jungle

Configuration

You can create the credential file yourself. By default, its location is at ~/.aws/credentials

[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY

You may also want to set a default region. This can be done in the configuration file. By default, its location is at ~/.aws/config

[default]
region = us-east-1

More detailed configurations can be found in the boto3 documentation.

Boto3 Doc - Configuration

jungle's People

Contributors

achiku avatar blackrobot avatar chrishenry avatar ctrlrsf avatar edubxb avatar moqada avatar mparramont avatar padilo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jungle's Issues

Support profile?

Dear Achiku,

Thank you for this cool script.

But some time admin need use different access_key by the help of profile. Would you add profile support later?

Thanks!

Jiming

work with different AWS profiles

I am trying this out for the first time, I was wondering if it does work with different profiles in the credentials file. I see its pulling with just the default profile..

Great tool btw...

mock_rds - postgresql+psycopg2

I am trying to mock the rds resource using moto and have done it in the below manner

from moto import mock_rds2
import boto3
from sqlalchemy import create_engine
import pytest

@pytest.fixture(scope='function')
def aws_credentials():
"""Mocked AWS Credentials for moto."""
os.environ['AWS_ACCESS_KEY_ID'] = 'testing'
os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing'
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
os.environ['AWS_SESSION_TOKEN'] = 'testing'

@pytest.fixture(scope='function', autouse=True)
def rds(aws_credentials):
with mock_rds2():
yield boto3.client('rds', region_name='us-east-1')

@pytest.fixture(scope='function', autouse=True)
def rds_instance(rds):
"""RDS mock service"""
test_instances = rds.create_db_instance(
DBName='test_db',
AllocatedStorage=10,
StorageType='standard',
DBInstanceIdentifier='instance',
DBInstanceClass='db.t2.micro',
Engine='postgres',
MasterUsername='postgres_user',
MasterUserPassword='p$ssw$rd',
AvailabilityZone='us-east-1',
PubliclyAccessible=True,
DBSecurityGroups=["my_sg"],
VpcSecurityGroupIds=["sg-123456"]
)
yield test_instances
# print(rds.describe_db_instances())
#
# db_instance = test_instances["DBInstance"]
# print(db_instance)
# user_name = db_instance['MasterUsername']
# host = db_instance['Endpoint']['Address']
# port = db_instance['Endpoint']['Port']
# db_name = db_instance['DBName']
# conn_str = f'postgresql+psycopg2://{user_name}:p$ssw$rd@{host}:{port}/{db_name}'
# print(conn_str)
# engine_con = create_engine(conn_str)
# engine_con.connect()

def test_conn(rds_instance):
db_instance = rds_instance["DBInstance"]
print(db_instance)
user_name = db_instance['MasterUsername']
host = db_instance['Endpoint']['Address']
port = db_instance['Endpoint']['Port']
db_name = db_instance['DBName']
conn_str = f'postgresql+psycopg2://{user_name}:p$ssw$rd@{host}:{port}/{db_name}'
print(conn_str)
engine_con = create_engine(conn_str)
engine_con.connect()

I am getting an error at the "engine_con.connect()"

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "instance.aaaaaaaaaa.us-east-1.rds.amazonaws.com" to address: Unknown host
E

tmux integration

It's nice to have functionality to ssh to multiple servers at once by specifying Tag:Name, and keep sending same commands, like top or less /path/to/log.

ec2 ls -l gives format error

File "/usr/local/lib/python3.6/dist-packages/jungle/ec2.py", line 22, in format_output
tag_name, i.state['Name'], i.id, i.private_ip_address, str(i.public_ip_address)))
TypeError: unsupported format string passed to NoneType.format

fix:
diff --git a/jungle/ec2.py b/jungle/ec2.py
index 963d1fc..1e4108d 100644
--- a/jungle/ec2.py
+++ b/jungle/ec2.py
@@ -18,7 +18,7 @@ def format_output(instances, flag):
for i in instances:
tag_name = get_tag_value(i.tags, 'Name')
out.append(line_format.format(

  •        tag_name, i.state['Name'], i.id, i.private_ip_address, str(i.public_ip_address)))
    
  •        tag_name, i.state['Name'], i.id, str(i.private_ip_address), str(i.public_ip_address)))
    
    return out

Tab characters cause misaligned overview in ec2 ls

When machine names have varying lengths the use of tab characters causes the columns not to be aligned properly (iTerm2, Mac OS X). I think this command should work out the maximum machine name length and pad all names with spaces, e.g.:

>>> '{:<10}'.format('name')
'name      '

Print ssh cmd

When running jungle ec2 ssh ... sometimes it gets a bit confusing, if jungle prints the cmd used in case of error it would be very nice to trobleshooting IMO.

I don't know if it should be a verbose mode, or just do this by default.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.