You’ll need an IAM user which has the permission to edit security groups attached to the ec2 instance. We need the IAM Access key and Secret key to run this script.
AWS-cli installed. If not, get it from here AWS CLI
After installing AWS CLI, it is required to create multiple profiles {in case multiple accounts of AWS are needed}. Refer this link to setup multiple accounts/profiles in AWS CLI.
- The script performs the following actions
- Pulls out your public IP from the web
- Adds "/32" after it and saves it to a file
- Reads the file and copies it to a variable
- Revokes the existing permissions of the specified security group
- Adds the new IP to the specified security group
- You can specify the security group id by replacing sg-xxxxxxxx with your security group id
- You can add multiple port access to your ip by copying the last line and replacing the port number
- Don't forget to modify the profile name yyyyyyy with your aws profile before using it
Happy Hacking..!! You just saved 3 minutes of your time by avoiding the whole UI related operations