I use Amazon EC2 every day and yet I always forget how to use their command-line tools. Here are a few common scenarios I run into, and their solutions.

Okay, just kidding, there's only one. I'm planning on editing this post over time :-)

Bundling an AMI from a running instance

  1. Use scp to copy your private key (pk-*.pem) to root@yourami:/mnt
  2. Log in as root and bundle the volume
    $ ec2-bundle-vol -d /mnt -k /mnt/pk-*.pem –cert /mnt/cert-*.pem -u YOUR_AWS_ACCOUNT_ID -s 10240

    Now you have several minutes to kill. Click play…

  3. Upload the image to Amazon S3. You may want to do this inside of screen; I had my ssh session time out on me while it was working a couple of times.
    $ s3cmd ls # List all S3 buckets
    $ ec2-upload-bundle -b YOUR_S3_BUCKET -m /mnt/image.manifest.xml
    $ ec2-upload-bundle -b YOUR_S3_BUCKET -m /mnt/image.manifest.xml -a YOUR_ACCESS_KEY -s YOUR_SECRET_ACCESS_KEY
  4. Register the AMI. This is something you need to do even when updating an image that has already been registered.
    $ ec2-register YOUR_S3_BUCKET/image.manifest.xml

    This will return an AMI identifier that can be used to run a new instance.

    $ ec2-run-instances YOUR_AMI_IDENTIFIER

More information on Creating an Image at Amazon