SSH into your EC2 instances with ease
ozkatz.github.io
ozkatz.github.io
Then have a bastion host in a DMZ that forward to the actual instances (I prefer 172 as it tends to avoid clashing with wifi networks). This does cost you a m1.small Amazon instance, but if you reserve it the cost is negligible.
Even better. You can do this automagically with ssh by putting a suitable `ProxyCommand ssh <bastion> "nc %h %p"` in your ssh config. So you just `ssh 172.0.0.10` or ssh `my-internal-name.blah` and it tunnels straight in for you.
You can pair this with internal DNS if you want to get really fancy - although it's a bit fiddly. From what I read internal DNS is pretty high up on the Route 53 feature request list.
http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-dn...
ProxyCommand ssh -W %h:%p <bastion>
this also means that netcat, or even a shell/ability to execute commands is not required on the remote bastion host.Then as part of my bootstrapping I register the VPC instance's internal-ip address on route53 under the my-internal-name.blah zone.
Then I can simply do ssh staging01, etc.
However, I would like to point out that the correct solution to this problem is DNS, as others here have indicated. Couple Route53 with something like Zonify (http://nerds.airbnb.com/easy-aws-inventorying-with-dns/) by the fine folks at AirBnB, and you've got something quite powerful that is diff'able via your normal tools, and can be easily versioned for sanity and safety.
Don't let my comments (or the comments of others here) detract from the pretty clever approach that you took. I think it's the fate of every ops/devops to, at some point in their careers, create a host address storage/querying system that contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of DNS without realizing it the first time around.
At organizations where I have held the above titled roles, DNS was one of first things to be put into service if it had not already been used. Connecting to the IP address of a dedicated machine by a nice name is pretty much what the DNS was invented for. DNS is very much not static and if you are changing a host's IP very often, you can set it up such that the DNS responds appropriately with the proper up to date IP address.
OP's script is nice but... it's solving an already solved problem, IMO.
host alias hostName thehostname user your_username
I like the work in the article, but many times when I think I need to whip up a sweet script to fix some problem in the terminal I find the old neckbeards already wrote it, polished it, and left it on the shelf for me to use.
>>ssh -i <yourkey> ec2-user@<yourinstance>.amazonaws.com
isn't it the easiest it can get to?