Add current instance IP into security group with AWS cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
Post a Comment