Overview
This guide will walk you through running your first security group audit using AWS Security Group Auditor. You’ll learn how to execute the tool, interpret the results, and safely clean up unused security groups.Before starting, make sure you’ve completed the installation steps and configured your AWS credentials.
Running your first audit
Navigate to the script directory
Open your terminal and navigate to the directory containing
check_sg_usage.py:Execute the auditor
Run the script using Python 3:The tool will immediately start the audit process.
Monitor the audit progress
As the script runs, you’ll see real-time output showing:
- Your AWS account ID
- Progress indicators for each security group
- Associated resources for each security group
Review the log file
The tool automatically generates a detailed log file named This file contains the complete audit results for future reference.
{account_id}_sg_log.txt in the same directory.Review unused security groups
After auditing all security groups, the tool displays a summary:These are security groups with no attached resources or references.
Decide on deletion (optional)
The tool will prompt you to confirm deletion:To delete unused security groups, type
sí, si, s, yes, or y and press Enter.To keep them, type no or n and press Enter.Understanding the output
The auditor checks each security group against 25+ AWS services. Here’s what different output messages mean:Resource associations
When a security group is in use, you’ll see lines like:| Output | Meaning |
|---|---|
Instancia EC2 asociada: i-0abc123def, Estado: running | Attached to an EC2 instance |
ALB/NLB Asociado: my-load-balancer | Attached to an Application/Network Load Balancer |
ELB Clásico Asociado: my-classic-lb | Attached to a Classic Load Balancer |
Instancia RDS Asociada: my-database | Attached to an RDS database |
ECS Servicio Asociado: my-service en Cluster: arn:aws:ecs:... | Attached to an ECS service |
Referenciado por otros SGs: sg-0abc123, sg-0def456 | Referenced by other security groups |
VPC Endpoint con SG: vpce-0abc123 | Attached to a VPC endpoint |
No associations
If a security group has no output after its header, it means no resources are using it.Common use cases
Audit-only mode
Run the tool to generate a report without deleting anything:no. You’ll have a complete audit log without making changes.
Scheduled audits
Run regular audits to track security group usage over time:Pre-cleanup review
Before cleaning up, review the log file to understand dependencies:Services checked
The auditor examines security group associations across these services:Compute
- EC2 instances
- ECS services
- EKS node groups
- Elastic Beanstalk
Databases
- RDS instances
- Neptune
- DocumentDB clusters
- Redshift clusters
- ElastiCache
Networking
- ELB (Classic)
- ALB/NLB (ELBv2)
- VPC Endpoints
- VPN Connections
Analytics
- Amazon MSK (Kafka)
- Glue jobs
- Elasticsearch
Development
- CodeBuild projects
- SageMaker endpoints
Other
- FSx file systems
- Amazon MQ brokers
- Transfer Family
- WorkSpaces
Troubleshooting
Permission errors
If you see permission errors, ensure your IAM user or role has the required read permissions:Deletion failures
Some security groups cannot be deleted due to dependencies:- Security group is referenced by another security group’s rules
- Resource using it was created after the audit started
- Default VPC security group (cannot be deleted)
No output or hanging
If the script appears to hang on certain services:- Large AWS accounts may take time to audit all resources
- Some services (like ECS) require pagination and may take longer
- Network issues can cause timeouts
Best practices
Next steps
Now that you’ve completed your first audit, consider:- Setting up automated audits using cron or AWS Lambda
- Integrating the tool into your infrastructure-as-code workflows
- Creating custom reports from the log files
- Implementing tagging strategies to track security group ownership
View source code
Explore the full source code and contribute to the project