This repository contains a custom script for performing an asset inventory of specific AWS resources across multiple regions. Designed to operate under the AWS SecurityAudit policy, the script efficiently gathers counts of EC2 instances, ECS clusters and instances, EKS clusters and nodes, and RDS instances without requiring full administrative permissions.
If you want to know more about this script and where it came from, read my article :https://medium.com/@kuroH/aws-script-inventory-5c0477603508
The AWS-Resource-Count-Script-SecurityAudit-Limited provides a secure and limited-access method to inventory AWS resources using a user account with the SecurityAudit Managed Policy. It’s designed for scenarios where administrators need to audit specific AWS resources but only have limited permissions.
Features:
- Counts EC2 instances, ECS clusters and container instances, EKS clusters and nodes, and RDS instances across multiple regions.
- Operates within the constraints of SecurityAudit policy, ensuring minimal permissions required.
- Outputs aggregated totals for each resource type.
- AWS CLI: Installed and configured with access to AWS resources.
- jq: A lightweight command-line JSON processor.
- Operating System: Tested on Ubuntu via Windows Subsystem for Linux (WSL) but can be adapted for other Linux environments.
- IAM Permissions: The AWS SecurityAudit Managed Policy attached to the user account.
- Regions: Due to limitations in the SecurityAudit permissions, which prevent access to all Regions and CloudShell, I'm using a script to retrieve the information. The Regions are manually specified. I've provided another script to list the enabled Regions in the current account.
-
Install WSL (for Windows users):
wsl --install
Restart your machine after installation.
-
Install jq:
sudo apt install jq
-
Install AWS CLI:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" sudo apt install unzip unzip awscliv2.zip sudo ./aws/install
-
Clone this repository and set script permissions:
git clone https://github.com/yourusername/AWS-Resource-Count-Script-SecurityAudit-Limited.git cd AWS-Resource-Count-Script-SecurityAudit-Limited chmod +x AWSInventoryScript.sh
-
Set up AWS environment variables (or configure using
aws configure
). For demonstration purposes, here’s an example with environment variables:export AWS_ACCESS_KEY_ID=your-access-key export AWS_SECRET_ACCESS_KEY=your-secret-key export AWS_DEFAULT_REGION=us-west-2
The above credentials are official sample data
-
Run the script:
./AWSInventoryScript.sh
The script will output the count of each resource type for all specified regions and provide a total summary at the end.If you want to quickly list the existing regions, you can run the list_aws_regions.sh file.
The script was scanned using Amazon CodeGuru for any security vulnerabilities and was found to have no critical issues.