Created
November 13, 2019 07:37
-
-
Save furio/80316ef8a37c52f241399722336ecf06 to your computer and use it in GitHub Desktop.
A bash function to update my IP in a sg on AWS
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
function __updateBastionHost { | |
AWSCOMMONARGS="--profile trans-prod --region eu-central-1" | |
AWSGROUPID=sg-0b304a3377f768295 | |
MYIP=$(curl -s v4.ifconfig.co) | |
MYIP=$(echo ${MYIP} | awk '{ print $0 "/32"}') | |
AWSSIP=$(aws ec2 describe-security-groups --group-ids $AWSGROUPID $AWSCOMMONARGS | jq -r '.[] | .[0] | .IpPermissions[] | select(.FromPort==22) | .IpRanges[] | select(.Description=="FurioThai") | .CidrIp') | |
aws ec2 revoke-security-group-ingress --group-id $AWSGROUPID $AWSCOMMONARGS --ip-permissions "[{"IpProtocol": "tcp", "FromPort": 22, "ToPort": 22, "IpRanges": [{"CidrIp": "'$AWSSIP'", "Description": "FurioThai"}]}]' | |
aws ec2 authorize-security-group-ingress --group-id $AWSGROUPID $AWSCOMMONARGS --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges="[{Description=\"FurioThai\",CidrIp=$MYIP}]" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment