Source: towardsthecloud.com

Clean up unused security groups in AWS
In this tutorial, we’ll show you how to use Python and the boto3 library to find and delete unused security groups in a single AWS Region. How to delete all unused security groups in an AWS Region

# https://github.com/dannysteenman/aws-toolbox # # License: MIT # # This script deletes all unused security groups in a single AWS Region import boto3 from botocore.exceptions import ClientError if __name__ == "__main__": ec2 = boto3.client("ec2") elb = boto3.client("elb") elbv2 = boto3.client("elbv2") rds = boto3.client("rds") used_SG = set()

The output will show the total number of security groups, the number of used security groups, the number of unused security groups, and the names and IDs of the deleted security groups.

In this tutorial, you’ve learned how to find and delete unused security groups in an AWS Region using a Python script based on the boto3 library.

Related Articles