-3

I have a list of 43 groups to delete from my AWS EC2, I'd like to know if is possible to delete the groups by AWS CLI command specifying the group names or from a list (cvs, txt, etc...).

FeDos
  • 13
  • 1
  • Possible duplicate https://stackoverflow.com/questions/49110/how-do-i-write-a-for-loop-in-bash – Mark B Jan 27 '21 at 18:26
  • Are you wanting to delete the Security Groups from AWS, or do you want to remove the Security Groups from a particular Amazon EC2 instance? – John Rotenstein Jan 27 '21 at 22:26
  • @John, I've been asked to delete all these groups that aren't used anymore, some of them are associated with instances or network interfaces. – FeDos Jan 28 '21 at 10:42

1 Answers1

2

If you wish to delete Security Groups from AWS, use the delete-security-group command. Please note that it only takes one Security Group at a time, so you would need to loop through a list and call it repeatedly.

Sometimes I just make an Excel spreadsheet to do this -- make a column of IDs, and then make a column with a formula of ="aws ec2 delete-security-group --group-id "&A1 -- then Copy Down to make all the commands. Finally, copy the commands and paste them into a Terminal window.

If you wish to remove Security Groups from an Amazon EC2 instance, use modify-instance-attribute. Provide the desired list of --groups that should be associated with the instance. It's not actually "deleting" the security groups. Rather, it is providing a list of Security Groups that should be associated with the instance. So, deleting lots of groups would be very fast -- just provide it with a list of Groups that should be associated with the instance.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470