Coder Social home page Coder Social logo

aws-ssh's Introduction

Description

This project is meant to facilitate ssh'ing into aws servers. Uses ec2 describe-instances to build a map of instance name to ssh host. Subsequently, a user can ssh using the instance name.

Install

Install steps for OSX

This library requires awscli (http://docs.aws.amazon.com/cli/latest/index.html) and jq (http://stedolan.github.io/jq/). Awscli can be installed via pip (which in turn can be installed via brew) and jq can be installed via brew.

brew install pip
pip install awscli
brew install jq
git clone [email protected]:lrajlich/aws-ssh.git
cd aws-ssh
make install

Configure

Make sure your AWS cli is configured, following steps here: (http://docs.aws.amazon.com/cli/latest/reference/configure/index.html)

In addition, this project has a "config" file, in the root folder of the project, to be modified as needed, with 3 parameters:

  1. user - user used to connect to AWS hosts
  2. pem - pem file used for ssh key authentication with aws servers
  3. host_xpath - Host to determine the host from the output of describe-instances. Some examples:
  • .PublicIpAddress - Use Public ip address as ssh host
  • .PrivateIpAddress - Use Private IP Address as ssh host
  • .PublicDnsName - Use Public DNS name as ssh host
  • .PrivateDnsName - Use Private DNS name as ssh host

If you edit the config file from the directory you git cloned into, you will have to run make install again as the config used by the command line is in the installed directory - /usr/local/aws-ssh/config (which installed via Make install).

Usage

Show options

  • aws-ssh help show available commands

List servers

  • aws-ssh ls show a list of aws instances
LUKEs-MacBook-Pro:~ lrajlich$ aws-ssh ls
app-01
app-02
app-03
consumer-01
consumer-02
consumer-03
resque-01
  • aws-ssh ls --help Show list of options
    • -d show details like instance id and ip address. Tab delimited
    • -r manually refresh the instance list (by default, it will use local cached list for speed)

Connect to server

  • aws-ssh app-01 Connect to server named app-01
    • This operates on grepping for the string, so things like aws-ssh con.*-01 will work
    • You can also connect using instance_id or ip address from aws-ssh ls -d

Scripting Examples

Scripting is fairly straightforward - aws-ssh ls -d is tab delimited and can be used for a number of use cases

  • aws-ssh ls -d | grep app-01 | cut -f 2 Get instance id for app-01, usage for AWS api operations on that server
  • aws-ssh ls -d | cut -f 3 | perl -pe "s/\n/,/g" Get comma seperated list of ip address, which can be used as argument to [pdsh -w](http://linux.die.net/man/1/pdsh parameter)

Auto-refresh

You can have aws-ssh updates it's listing automatically, though this requires a manual step. This is run off a cron job. First you need to create log directories for aws-ssh auto refresh. When auto refresh runs, any stdout and stderr will be written to this location.

sudo mkdir -p /var/log/aws-ssh
sudo chown `whoami` /var/log/aws-ssh

Create cron job fo OSX

run crontab -e. In Vim, enter the following line

*/5 * * * * /usr/local/aws-ssh/aws-ssh-auto-refresh >> /var/log/aws-ssh/cron.log 2>> /var/log/aws-ssh/cron.log

Press esc and then ZZ. This will install your cron tab (if you don't have one). Otherwise, you can do a simple write+quit vim operation.

aws-ssh's People

Contributors

lrajlich avatar

Watchers

James Cloos avatar  avatar

aws-ssh's Issues

Support "cached" ls (do not hit aws ec2 describe-instances)

ls can take a long time if the instance list is long... Support explicit parameters for --refresh and --cached

Command syntax:
aws-ssh ls --refresh
aws-ssh ls -r
aws-ssh refresh (same as ls -refresh)
aws-ssh ls --cached
aws-ssh ls -c

Create auto-refresh

create cron job that automatically polls aws ec2 describe-instances every few minutes and make aws-ssh ls default to using cache.

Command syntax:
aws-ssh start-auto-refresh
aws-ssh stop-auto-refresh

Filtering bug with substring

LUKEs-MacBook-Pro:~ lrajlich$ aws-ssh ls
...
torometrics-staging
torometrics-staging-resque-01
torometrics-test
LUKEs-MacBook-Pro:~ lrajlich$ aws-ssh torometrics-staging
Connect to torometrics-staging - 54.87.xx.xx 23.21.xx.xx
bash: 23.21.xx.xx: command not found

Grabs ip address for both torometrics-staging and torometrics-staging-resque-01

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.