Adding your public IP to a security group can have security risks. Please use the following script responsibly and with the understanding, it could potentially open a security hole in your operations. Use with extreme caution that it is to be used only on assets that aren't connected to sensitive data.
Note: I really don't want to discuss the security issues behind the following snippet. It is what it is. In a simple setup, I need a simple solution. This is just that...
I work remote 800 miles away using a residential network connection that uses dynamic public IP addresses. This can be quite the nuisance when you want to jump on an Amazon instance to perform a task quickly but can't because the IP range that had your old public IP for the assigned port is no longer valid. Then you have to log into AWS, 2FA, go find the instance, find it's security group, edit the inbound ports, find your IP range, edit the range's CIDR and then save it.
Ok. NOW I can get back to work...
I decided this was obnoxious. So I went the route of a Powershell script that will periodically run that will run through the assigned Security Groups I need access to in the regions I need to update. It will see if the IP range is there and if so, check the CIDR to see if it matches my public IP address. If it does, do nothing. If it doesn't, then it will revoke the range and re-add it with my current public IP address.
Other things you can do is have a flag to pass in that can delete the IP Ranges when you are finished so you can be assured to seal off access except when you intend to have it.
If you have a better way or a more automated way, please comment. I'd love to see what people come up with.