This Python script provides a command-line interface to gather inventory information from various AWS services within a specified region or globally where applicable. It helps in quickly listing resources such as EC2 instances, S3 buckets, RDS databases, and more, along with key configuration details.
The script can inventory the following AWS services:
- EC2 Instances
- Security Groups (including inbound and outbound rules)
- IAM Users (including MFA status, access keys presence, and attached policies)
- AWS Backup (Vaults, Plans, Protected Resources)
- AWS KMS Keys
- AWS Transfer Family Servers
- AWS WAFv2 Regional Web ACLs and Rules
- Amazon ECR Repositories
- Amazon EKS Clusters
- Amazon EFS File Systems
- Amazon GuardDuty Detectors
- Amazon MemoryDB Clusters
- Amazon RDS Instances
- Amazon S3 Buckets (global list)
- Amazon VPCs
- Amazon CloudWatch Alarms
- Elastic Load Balancers (Classic and v2)
- List all available AWS regions
- Python 3.6 or higher
boto3AWS SDK for Python- AWS credentials configured (e.g., via environment variables, shared credential file
~/.aws/credentials, or IAM roles). The script will use the default credential provider chain.
- Clone the repository (or download the script):
git clone <repository_url> cd aws-inventory
- Install the required Python package:
pip install boto3
Run the script from your terminal.
By default, the script inventories the ap-northeast-1 region. You can specify a different region using the --region argument.
python aws-inventory.py --region us-east-1Replace us-east-1 with the desired AWS region.
To see a list of all regions you can inventory, use the --list-regions flag.
python aws-inventory.py --list-regionsWhen using --list-regions, the script will only list regions and will not perform any inventory scans.
The script prints the inventory information directly to the console, grouped by service and region.
### EC2 Inventory (us-east-1) ###
Instance ID: i-xxxxxxxxxxxxxxxxx
Name: MyWebServer
Instance Type: t2.micro
State: running
Launch Time: 2023-10-27 10:00:00+00:00
VPC ID: vpc-xxxxxxxxxxxxxxxxx
Subnet ID: subnet-xxxxxxxxxxxxxxxxx
Private IP Address: 172.31.x.x
Public IP Address: 54.x.x.x
VPC Name: ProductionVPC
Subnet Name: PublicSubnetA
Security Groups:
- Group ID: sg-xxxxxxxxxxxxxxxxx
Group Name: web-access
Attached Volumes:
- Volume ID: vol-xxxxxxxxxxxxxxxxx
Size: 8 GB
Volume Type: gp2
State: in-use
Encrypted: False
Tags: {'Name': 'MyWebServer', 'Environment': 'Prod'}
--------------------
### Security Groups (us-east-1) ###
Security Groups:
- Group ID: sg-xxxxxxxxxxxxxxxxx
Group Name: web-access
Description: Security group for web servers
VPC ID: vpc-xxxxxxxxxxxxxxxxx
Inbound Rules:
- Protocol: tcp
Port Range: 80-80
IP Ranges: 0.0.0.0/0
- Protocol: tcp
Port Range: 22-22
IP Ranges: 1.2.3.4/32
Outbound Rules:
- Protocol: -1
Port Range: N/A-N/A
IP Ranges: 0.0.0.0/0
--------------------
... (output for other services)
The script is organized into functions for each AWS service inventory task and uses the argparse module to handle command-line arguments. It iterates through resources using the boto3 client for each service and prints relevant details. Error handling is included for API calls.