Getting started with Amazon Python AWS CLI tool

The new Amazon AWS CLI tool coded in Python is far superior to the old Java implementation. The official docs can be found at https://github.com/aws/aws-cli but here’s a quick run down of how I install and configure:

Installation

or if you’re not using a virtual environment

You can also use easy_install in the same way if you prefer

Configure Environment Variables

Add the following to your .bash_profile, .bashrc, or .profile:

The key ID and secret key are required, the default region means you do not need to specify the region for every command, and the default output, changes the output type; it is set to JSON by default, which is fine for scripting, but not the best for reading in a terminal.

You can also just specify an environment variable to point to a config file and add the credentials and options there (see the github wiki)

Enable auto-complete

Add the following line to your .bash_profile, .bashrc or .profile

Finishing and test

To apply the changes to your environment and test, run the following:

The first command will apply the environment changes, the second should display all instances in the default region, using your default output type ( I prefer text). The final line should prompt to display all options, and then list all available AWS sub-commands.

iTerm2 Keybindings for OS X

Word Jumping

If you use a mac and tried the iTerm2 application, you may have noticed that the keybindings for word jumping and deletion are not set up correctly. Here’s how to fix that:

From the iTerm2 menu select Preferences > Profiles and from the right select Keys. Now add the following key bindings by clicking (+) for each:

Alt + Left
Send Escape Sequence, Esc + b

Alt + Right
Send Escape Sequence, Esc + f

Alt + Backspace
Send Hex Code, 0x17

Split Terminals: Creating and Navigating

I also like to bind keys to split the terminal vertically and horizontally and move focus between them.

From the iTerm2 menu select Preferences > Profiles and from the right select Keys. Now add the following key bindings by clicking (+) for each:

Alt + Up
Split Horizontally with <profile>

Alt + Down
Split Vertically with <profile>

Cmd + Up
Select Split Pane Above

Cmd + Down
Select Split Pane Below

Cmd + Left
Select Split Pane on Left

Cmd + Right
Select Split Pane on Right

A simple cloud-init trick

If you use Amazon Web Services or other cloud providers that make use of cloud-init, you may occasionally have reason to re-trigger the initial cloud-init run; usually because something didn’t work quite right the first time round. Rather than having to kill the cloud instance and booting a fresh one, you can try this simple trick to trigger cloud-init on reboot: