Add current instance IP into security group with AWS cli

#!/bin/bash
# Set Security Group id. ID is better than name if not in default VPC
SG_ID="sg-goyun"
# Retrieve current IP address
IP=`curl -s http://checkip.amazonaws.com/`
# Authorize access on ports 22
aws ec2 authorize-security-group-ingress --group-id "$SG_ID" --protocol tcp --port 22 --cidr "$IP/32"
# To remove
$ aws ec2 revoke-security-group-ingress --group-id "$SG_ID" --protocol tcp --port 22 --cidr "$IP/32"

Comments