Getting Started with Amazon AWS Command Line Basics

I didn’t even realize there’s a set of command line tools for working with Amazon’s Web Services.  It only took a few mins to get started, but it wasn’t immediately apparent what needed to happen.

I’m using OSX Lion.  If you’re using another *nix this is all fairly easy to translate. I have no idea how this could be Windows-ified…

Download and Install

I downloaded the tools as a zip archive from http://aws.amazon.com/developertools/351.  I like to keep this kind of package within a ~/local folder, so:

mkdir ~/local
cd Downloads
unzip ec2-api-tools.zip
mv ec2-api-tools-1.5.3.1 ~/local

To make upgrades easier, create a symlink to that directory:

cd ~/local
ln -s ec2-api-tools-1.5.3.1 ec2-api-tools

Security

You need your username and password to get into the AWS web interface.  You’ll still need to authenticate with the command line tools, but you have a more convenient mechanism to do this – X.509 keys.

Log into the AWS web page, and go to My Account > Security Credentials.  Go to the X.509 Certificates tab and hit Create A New Certificate.  Download the private key and the certificate and save them somewhere safe – since it already has appropriate permissions and contains keys, I save mine to ~/.ssh/pk.pem and ~/.ssh/cert.pem respectively.

Configure

The tools require you to set JAVA_HOME and EC2_HOME environment variables, and there are a couple of other variables that will save you a whole lot of typing. Add the following to the end your ~/.bash_profile:

export PATH=$HOME/local/ec2-api-tools/bin:$PATH
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
export EC2_HOME=$HOME/local/ec2-api-tools
export EC2_PRIVATE_KEY=~/.ssh/pk_ec2.pem
export EC2_CERT=~/.ssh/cert_ec2.pem
export EC2_URL=https://ec2.us-west-1.amazonaws.com

Be careful with the last of these.  I host my instances in the US-West-1 region – you will likely need to figure out which URL to put here based on the region your instances or volumes are at.  If you have machines in multiple regions, use the --region switch in the commands instead.

Source the file to have the changes take effect:

. ~/.bash_profile

and carry on.

Run

Now, it’s easy.  For example, run ec2-describe-instances – it should show you a list of all your EC2 instances, and a whole bunch of info about them.  I leave it to you to work out the other 280-odd commands.  Looks like you can do pretty much do any operation to manage EC2 instances, images, volumes, networking, snapshots, …


Building NodeJS on OS X 10.5.8

It seems that I borked xcode, did something bad with my libssl, or just that my system’s too out of date to trivially install, homebrew or build NodeJS. I really want to install Node, so here’s what I just did.

I started off downloading and extracting the latest NodeJS source tarball (0.4.2 at time of writing). After attempting to configure and build, I was getting some complaints out of make:

I was getting some complaints out of make:

../src/node_crypto.cc: In function ‘void node::crypto::InitCrypto(v8::Handle)’:
../src/node_crypto.cc:2917: error: ‘SSL_COMP_get_compression_methods’ was not declared in this scope
Waf: Leaving directory `/Users/Ian/node-latest-install/build'
Build failed:  -> task failed (err #1):
	{task: cxx node_crypto.cc -> node_crypto_4.o}

After a helpful tweek from @tonymilne I looked at the output of ./configure slightly more closely: whilst it reported it found header openssl/crypto.h, it said that openssl was not found.

Getting an updated version of OpenSSL was pretty easy with homebrew:

brew create http://www.openssl.org/source/openssl-0.9.8r.tar.gz
brew install openssl

It didn’t quite fully install though. It told me “This formula is keg-only, so it was not symlinked into /usr/local”, and that

If you build your own software and it requires this formula, you'll need
to add its lib & include paths to your build variables:

  LDFLAGS: -L/usr/local/Cellar/openssl/0.9.8r/lib
  CPPFLAGS: -I/usr/local/Cellar/openssl/0.9.8r/include

Turns out that similar but different problems were solved by setting options with configure, and running ./configure --help in the folder with the NodeJS source shows some pertinent options. I tried

./configure --prefix=~/local --openssl-includes=/usr/local/Cellar/openssl/0.9.8r/include  --openssl-libpath=/usr/local/Cellar/openssl/0.9.8r/lib

and it seems like it was successful – node --vars includes -DHAVESSL=1.


The Compleat ATtiny13 LED Flasher: Part 3 – Low Power Mode

This is the final part of three in attempting to explain how to make the ATtiny13 flash a LED.

In previous posts we’ve looked at creating a simple LED flasher circuit for the ATtiny, a first-pass program for the ATtiny using delays, and a second-pass implementation exploiting timer overflows resulting in a simpler program.  In this article I will explore the power saving modes on the ATtiny13 as an example of how to minimize the power consumption of your circuit.  If your ATTtiny13-, ATtiny80-, or even ATmega-based circuit relies on battery power you will be able to significantly improve the battery life by using the chips’ power saving modes.

In this article we will be using the same circuit developed in the previous posts:

Read more »


The Compleat ATtiny13 LED Flasher: Part 2 – Using Timer Interrupts

This is the second part of three in attempting to explain how to make the ATtiny13 flash a LED.

Post-Pre-script: If you find this post useful, happen to try out the code, or have any other views or criticisms, please leave a comment. I’d love to hear what you think.
- Ian

So last time around, we made a LED flash.  Of course there are other, more elegant ways to do it.  In this post I’ll explore interrupts, and specifically the timer overflow interrupt.  For this I’ll use the same circuit setup from the first article.  If you’re reading this one independently, here’s a circuit diagram:

Read more »


The Compleat ATtiny13 LED Flasher: Part 1 – Setup, Hardware and A Basic Solution

This is the first part of three in attempting to explain how to make the ATtiny13 flash a LED.

If you’re used to the user-friendliness of Arduino, getting started with bare bones AVRs can be hard work.  I’d like to try to go slowly through the early steps and point out some of the information sources I used.

First, start at the end: here’s the final circuit.  It has an ATtiny13, an LED and current-limiting resistor, a few wires, the programmer interface, and that’s about it.  All it does is flash the LED on and off (very much like the classic 555 timer astable multivibrator but with the advantage of no passive components required).  That’s it.  Not much to it.

Also, here’s a quick sketch of a circuit diagram too – the inputs all come directly from the ISP interface from the programmer.

Ok, that’s the end result.  Next: how to get there:

  1. Prerequisites (hardware and software)
  2. Build the circuit
  3. Write code
  4. Upload to microprocessor

Read more »