Skip to content

Instantly share code, notes, and snippets.

@furio
Created November 13, 2019 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furio/80316ef8a37c52f241399722336ecf06 to your computer and use it in GitHub Desktop.
Save furio/80316ef8a37c52f241399722336ecf06 to your computer and use it in GitHub Desktop.
A bash function to update my IP in a sg on AWS
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