Tired of updating your IP address manually in the security group eveytime you need to access a EC2 instance? Look no further :)
$ mkdir ~/.aws/cli
$ cat >> ~/.aws/cli/alias
update-ssh-ip =
!f() {
MYIP=$(curl -s -4 ifconfig.co)
cat <<EOF > /tmp/aws-update-inbound-ssh-traffic.json
{
"IpPermissions": [
{
"PrefixListIds": [],
"FromPort": 22,
"IpRanges": [
{
"CidrIp": "$MYIP/32"
}
],
"ToPort": 22,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
}
],
"GroupName": "default",
"GroupId": "sg-4815ef2c"
}
EOF
aws ec2 authorize-security-group-ingress \
--group-id sg-4815ef2c \
--cli-input-json file:///tmp/aws-update-inbound-ssh-traffic.json
}; f
Finally just run:
$ aws update-ssh-ip