Log file location
The audit creates a log file named after your AWS account ID:123456789012_sg_log.txt
This file is created in the same directory where you executed check_sg_usage.py.
Output structure
The log file contains three main sections:1. Header section
The file begins with the account identification:2. Security group analysis section
Each security group is analyzed in a dedicated section:- Separator line:
------------------------------------------------marks the start of each security group - Header line: Shows the progress counter
(5/47), security group IDsg-0a1b2c3d4e5f6g7h8, and description(Web Server Security Group) - Association lines: Indented with tabs, listing each resource using this security group
3. Results summary section
The file ends with:Understanding “associated” vs “not associated”
A security group is considered associated (in use) if:It's attached to EC2 instances
It's attached to EC2 instances
It's used by load balancers
It's used by load balancers
Classic Load Balancer:Application/Network Load Balancer:
It's attached to RDS databases
It's attached to RDS databases
It's used by ECS services
It's used by ECS services
It's associated with EKS node groups
It's associated with EKS node groups
It's used by other AWS services
It's used by other AWS services
The tool checks 20+ AWS services including:
- CodeBuild:
Proyecto CodeBuild Asociado: build-project - Redshift:
Clúster Redshift Asociado: analytics-cluster - ElastiCache:
Instancia ElastiCache Asociada: redis-cache - MSK (Kafka):
Clúster Kafka Asociado: events-kafka - Neptune:
Instancia Neptune Asociada: graph-db - DocumentDB:
Clúster DocumentDB Asociado: document-store - Elastic Beanstalk:
Entorno Elastic Beanstalk Asociado: production-env - SageMaker:
Endpoint de SageMaker Asociado: ml-endpoint - Transfer Family:
Servidor AWS Transfer Family Asociado: s-1234567890abcdef0 - Glue:
Trabajo de Glue Asociado: etl-job - Elasticsearch:
Dominio de Elasticsearch Asociado: logs-domain - Amazon MQ:
Broker de Amazon MQ Asociado: message-broker - FSx:
Sistema de archivos Amazon FSx Asociado: fs-0a1b2c3d4e5f6g7h8 - WorkSpaces:
Directorio Amazon WorkSpaces Asociado: d-1234567890 - VPC Endpoints:
VPC Endpoint con SG: vpce-0a1b2c3d4e5f6g7h8
It's referenced by other security groups
It's referenced by other security groups
- It has no resources attached to it
- No other security groups reference it in their rules
- The section for that security group shows only the header with no indented association lines
Reading the output sections
Example: Security group with associations
- This security group is actively in use
- It protects 2 running EC2 instances
- It’s attached to an Application Load Balancer
- The database tier security group references this SG (likely allowing traffic from web to database)
- This security group should NOT be deleted
Example: Security group without associations
- No indented lines appear after the header
- This security group has no associated resources
- It’s safe to delete (but verify the description to ensure it’s not needed)
- This will appear in the final results summary as unused
Identifying which resources use which security groups
To find all resources using a specific security group:- Search the log file for the security group ID (e.g.,
sg-0a1b2c3d4e5f6g7h8) - Look at all the indented lines in that section
- Each indented line represents a resource attachment
- 3 EC2 instances (2 running, 1 stopped)
- 1 ECS service
- Referenced by 2 other security groups
Common patterns in results
Pattern 1: Default VPC security group
Default security groups often appear unused but cannot be deleted. AWS creates them automatically for each VPC.
Pattern 2: Security group used only for references
Pattern 3: Orphaned security groups
Next steps
After reviewing the results:- Delete unused security groups through the interactive prompt
- Archive the log file for compliance and audit records
- Re-run the audit periodically to catch newly unused security groups