Answers for "configure my aws security group for my ip"

0

add my ip to aws security group cli

# Retrieve current IP address
$IP=Invoke-WebRequest -UseBasicParsing http://whatismyip.akamai.com/
$sg="sg-00001"
$old_file_path = 'old_ip.txt'

if(Test-Path -Path $old_file_path){
    $OldIp=Get-Content -Path $old_file_path
    aws ec2 revoke-security-group-ingress --group-id "$sg" --protocol tcp --port 8443 --cidr "$OldIp/32"
}

aws ec2 authorize-security-group-ingress --group-id "$sg" --protocol tcp --port 8443 --cidr "$IP/32"

Set-Content -Path $old_file_path -Value $IP
Posted by: Guest on October-02-2021

Browse Popular Code Answers by Language