Here’s a quick tip to add your IP address to a pre-built security group, for easy access to VMs on the move.

You’ll need to have created your security group already and given it a name, like john in the one below.

#!/bin/bash
var1="aws ec2 authorize-security-group-ingress --group-name john --protocol tcp --port 22 --cidr "
var2=`curl http://icanhazip.com`
echo $var1 $var2"/32"

I use this in TextExpander which means I can just type:

;sg

And it’s updated and I’m ready to go!