I’m running multiple different project on AWS which was so much of a pain to use, as I often find myself having to use the identity of project-a together with the official amazon ec2 tools.
To help myself manage the multiple identities, I wote a set of bash functions, called:
aws_load <config-name> – loads configuration from config-name
ec2ssh <instance-number-in-ec2din-list> – ssh’s into a given instance, with the root key
ec2scp – a shorthand for scp -i <keyfile>
I keep the configuration files in the directory ~/amazon/conf/name.sh and keypairs in ~/amazon/keypairs/ but that should be obvious to change.
To change or load an identity, one simply calls the function from a shell prompt like so:
mads@workmads ~ % aws_load some-identity
loaded certificate ...
loaded /Users/mads/amazon/conf/some-identity.sh (...)
I hope someone finds this as useful as I do.
Functions (could be placed in .bashrc or .zshrc).
function aws_load {
if [ -n "$1" ]; then
ec2_configurations="$HOME/amazon/conf"
ec2_keys="$HOME/amazon/keypairs"
conf="$ec2_configurations/$1.sh"
if [ -x "$conf" ]; then
unset AMAZON_ID AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_CERT EC2_PRIVATE_KEY EC2_CERT AWS_KEYPAIR_NAME
source $conf
if [ -n "$AWS_KEYPAIR_NAME" ]; then
export AWS_SSH_KEY="$ec2_keys/id_rsa_${AWS_KEYPAIR_NAME}-keypair"
fi
if [ -n "$AWS_CERT" ]; then
export EC2_PRIVATE_KEY=~/.ec2/pk-$AWS_CERT.pem
export EC2_CERT=~/.ec2/cert-$AWS_CERT.pem
echo "loaded certificate $AWS_CERT"
fi
echo "loaded $conf ($AMAZON_ID)"
else
echo "configuration $conf not found (or not executable)"
fi
else
echo "usage: aws_load <configuration name>"
fi
}
function ec2ssh {
if [ -n "$1" ]; then
HOST="`ec2din | awk '/i-/ {print $4}' | tail +$1 | head -n 1`"
ssh -i $AWS_SSH_KEY -l root ${HOST}
else
echo "Please write a number"
fi
}
function ec2scp {
scp -i $AWS_SSH_KEY $@
}
Configuration “file” template to be placed in ~/amazon/conf/<config-name>.sh:
#!/bin/sh
export AMAZON_ID=""
export AWS_ACCESS_KEY_ID=""
export AWS_SECRET_ACCESS_KEY=""
export AWS_CERT=""
export AWS_KEYPAIR_NAME=""
Happy identity switching.
Posted by Mads Sülau Jørgensen at 4:50 pm on July 22nd, 2009.
Categories: Python, Work.
Until recently I’ve been using the file:// django cache, but that has a “problem” when multiple users needs to manipulate the cache (think uid 80 writes a key, that uid 1000 wants to delete).
My problem with the memcached:// django cache provider has been, that it cannot handle being used on a shared memcached instance, because of the danger of key collissions.
More… »
Posted by Mads Sülau Jørgensen at 1:23 pm on June 23rd, 2009.
Categories: Django, Programming, Python, Work. Tags: cache, Django, memcached, prefix.
While working on a project using PyAMF today, i was about to write a unittest of a service method, when I realized that it would be harder than necessary to make unittests of the service. The cause of this is, that there was no test client wrapper for the django test client for pyamf, which means, that to do a unittest of the gateway, you’ll have to start a django server, and run a unittest elsewhere.
Seeing as how there are a lot of benefits to using djangos own test suite (fixtures and automatic database generation to name a few), i set out to write a little test client for PyAMF to utilize django’s test client, so it would be possible to write a proper test suite.
This turned out great, and is now ticket 508 over at PyAMFs trac. Look at the client.py for the code. At some point, it will be integrated into PyAMF mainline as p.r.c.django.TestClient (or something like that).
Posted by Mads Sülau Jørgensen at 3:18 pm on April 21st, 2009.
Categories: Django, Programming, Python, Work, flash. Tags: Client, Django, PyAMF, Test.
Having searched a lot around google, it does not seem that anyone has published their trac commit hooks for mercurial. Since I had to use just that, I’ve cooked up a little hook which is based on the hook from the timingandestimationplugin. I’ve created it as a changegroup hook, and it’s probably filled with bugs, but it seems to work and it catches the fixes #42 and such.
To use the hook you must place it somewhere inside your PYTHONPATH and tell mercurial to use it (I placed it in a module called trachook — don’t call your module trac):
[hooks]
changegroup = python:trachook.hook
And tell the hook where to find your trac installation:
[trac-hook]
root = /path/to/trac
url = http://url/to/trac
Grab your own copy of the source, and happy coding. And a big thank you to Jesper Nøhr.
Also, if you need a place to host your mercurial repository but don’t wan’t to set it up yourself, check out bitbucket.
Posted by Mads Sülau Jørgensen at 4:03 pm on October 13th, 2008.
Categories: Python, Ramblings, Work.
At work we yestoday decided to update our internal url structure for our client test sites, issue management systems and such arround a bit. Seeing as we decided on purchasing a genuine signed ssl wildcard certificate, we needed to change our url’s a bit.
More… »
Posted by Mads Sülau Jørgensen at 8:36 pm on March 19th, 2008.
Categories: Apache, Django, Python, Work. Tags: Apache, coniuro aps, Django, mod_macro, Python.
The code for a very simple asynchronous socket server written in python utilizing the asynchat module. It’s all in good fun.
More… »
Posted by Mads Sülau Jørgensen at 3:39 pm on February 21st, 2008.
Categories: Programming, Python, Work. Tags: asynchat, asyncore, Python, server, socket.