Generating SSH config from AWS hosts using boto

  As a consultant and advisor to many firms running on or investigating AWS, I find SSH host and key management to be a constant struggle.  From IAM credentials to default OS logins, it’s easy to lose time with constant lookups.  Over time, I’ve written a few tools that make it easier to quickly “chroot” or “virtualenv” your SSH environment.  Below is a small example of the logic and usage pattern that I’ve found to be very helpful:

  1. First, make sure you have boto installed and configured:
  2. Next, wget my gist or copy-paste the code embedded below into a file.
  3. Run the script and pipe output to a named SSH configuration file:
    • python generate_aws_ssh_config.py > ~/.ssh/bcllc_config
  4. At this point, you’ll have an SSH configuration file with the following details.  If any assumptions are incorrect, manually edit the file.
    • A host entry for all reservations; yes, even stopped ones!
    • The host entry name is pulled from the EC2 tag “Name” if exists, else instance ID.
    • The default SSH user is pulled from the EC2 tag “user” if exists, else set to default (e.g., ubuntu).
    • You do automatically tag your instances with variables when you provision them, right? . . .
    • The key/identity file is set to the ~/.ssh/{keypair-name}.pem.  Basically, if you save the keys as generated into your ~/.ssh/ folder, you should be fine.
  5. Next, we’re going to create an alias for ssh in your ~/.bashrc:
    • alias vssh='ssh -F $VSSH_CONFIG'
  6. When you want to switch between client sandboxes, you then simply export VSSH_CONFIG to the named config file and proceed:
    • export VSSH_CONFIG=~/.ssh/clientA_config
    • vssh web-tier-0
    • export VSSH_CONFIG=~/.ssh/clientB_config
    • vssh postgres-0

It’s easy to see how this logic can be extended into segregated virtualenv-style SSH environments, as well as aliases for `rdesktop` on Windows servers.

Happy shelling!  And, as promised, script embedded below:

Tagged with: , , , , ,
Posted in Consulting, Programming

Slides from ReInvent Law Silicon Valley Talk

Live from ReInvent Law Silicon Valley, where I gave an Ignite-style talk drawing analogy to law’s future from finance’s past.  Slides embedded below and video forthcoming:

Tagged with: , , ,
Posted in Consulting, Finance, Law

Automating Oracle Database deployment with Amazon Web Services, fabric, and boto – SEMOP Talk, Feb 12, 2013

I’ll be giving a talk tonight on automated Oracle database deployment at the SouthEast Michigan Oracle Professionals (SEMOP) Meetup Group.

While I’ll be following up on this post later, I wanted to share the slides and Github repository for participants to follow along:

Tagged with: , , , , , ,
Posted in Consulting, Programming

Git Repository for Congressional Bill Statistics

  After a nice twitter conversation this morning, I finally got the impetus to release the source for my Congressional Bill Statistics data.

  You can find the source at this Github repository.  I haven’t taken the time to review licensing yet, but I won’t be asserting anything more than CC3 Attribution on my code.  Please feel free to `git clone` and improve!

Tagged with: , , , ,
Posted in Law, Programming, Research

Connecting R to an Oracle database with RJDBC

In many circumstances, you might want to connect R directly to a database to store and retrieve data.  If the source database is an Oracle database, you have a number of options:

  Using ROracle should theoretically provide you with the best performing client, as this library is a wrapper around the Oracle OCI driver.  The OCI driver, however, is platform-specific and requires you to install Oracle database client software.

   Using RODBC for Oracle is like using an ODBC connection for any database; so long as your platform provides an ODBC manager and drivers, you are OK.  On Linux, this means unixODBC, and on Windows, this means the Oracle Data Access Components package.

What if you don’t want to write code that is either platform-specific or requires relatively complex, platform-specific installation steps?  In this case, you should consider using RJDBC.

  I’ll assume that you have a JRE/JDK installed and know the path to your JAVA_HOME.

  The first step is to obtain the Oracle JDBC drivers, e.g., the 11gR2 release drivers.  You can pick the lowest compatible Java version you’d like to support; I’m using ojdbc6.jar, which should support Java 6+.
  Next, make sure you know how to connect to your source database.  You’ll need the following information for your database listener:
  • Hostname or IP, e.g., database.company.com
  • Port, e.g., 1521
  • Service name or SID, e.g., ORCL
  • Username
  • Password

This information will allow us to construct the DSN, which will look something like this:  jdbc:oracle:thin:@//hostname:port/service_name_or_sid

Armed with this DSN and your Java home, you should now be able to modify and execute the example below.

Tagged with: , ,
Posted in Consulting, Programming