I made a mistake and have 1 security group across 365 instances, which I’m not willing to manually remove. Is there a Python script out there, maybe using BOTO3 that will cycle through all instances, find the security group, and remove it? I’ve been looking through this documentation, but haven’t been able to figure out how to apply it to a script yet (I’m a python noob)
.
.
Edit Thanks to /u/thisisthetechie for the [solution found here](comments : aws
/8d94uk/looking_for_a_script_to_remove_a_security_group/dxn3ulx/)
AWS Tools for Windows PowerShell worked perfectly after initial set up and was way better than trying to figure out the Python route. Cheers.
do you have a list of all the instances affected? if so why not loop through them with the “delete-security-group” command and then read each line from the file and provide the instance ID?
You can import resources into terraform, so could import all your existing ones but this would need some scripting (looping), certainly if you have one security group per instance (I may have misunderstood this).
I can’t be much more help as I’m on my phone on the beach enjoying the last few days of a very much needed holiday
Edit: probably worth just scripting this in AWS CLI in bash or whatever you know how to use. Going forward though, definitely look at IaC (infrastructure as code).
Do you need to use Python? The AWS Cli tools on Linux and AWS .NET SDK for Powershell are more than adequate options for making your life a lot easier.
It doesn’t look that messy to me. Looks like exactly what I need and just didn’t know how to write that myself!
Currently I’m just having an issue with Edit-EC2InstnaceAttribute. It says that I am not authorized to perform that operation even though I am a full admin in IAM.
Once I investigate that I will get back to you.
Update Worked like a charm. What are you talking about freaking messy? You are a hero and a scholar.
Not to seem like an ass, but if you couldn’t write that yourself based on the API docs, you really need to spend some time brushing up on your automation and scripting or you’re going to find yourself out of a job very quickly.