This script automates the process of listing resources in an AWS account for a specified service and region using the AWS Command Line Interface (CLI). It simplifies the task of auditing and managing your AWS resources by providing a quick overview of the specified service's resources.
The script supports the following AWS services:
- EC2 - Elastic Compute Cloud instances.
- RDS - Relational Database Service instances.
- S3 - Simple Storage Service buckets.
- CloudFront - Content Delivery Network distributions.
- VPC - Virtual Private Cloud configurations.
- IAM - Identity and Access Management users and roles.
- Route53 - DNS and domain management.
- CloudWatch - Monitoring and logging services.
- CloudFormation - Infrastructure as Code stacks.
- Lambda - Serverless function services.
- SNS - Simple Notification Service topics.
- SQS - Simple Queue Service queues.
- DynamoDB - NoSQL database tables.
- EBS - Elastic Block Store volumes.
- AWS CLI: The AWS CLI must be installed and configured on your system.
- AWS Configuration: Ensure the AWS CLI is configured with appropriate credentials and default settings.
If you haven't installed the AWS CLI, you can do so by following these instructions:
# On macOS
brew install awscli
# On Linux
sudo apt-get update
sudo apt-get install awscli
# On Windows
Download the installer from the [AWS CLI installation page](https://aws.amazon.com/cli/).
- Clone the repository or download the script.
- Open your terminal and navigate to the directory containing the script.
- Make the script executable (if it’s not already):
chmod +x aws_resource_listing.sh
- Run the script with the desired service and region:
./aws_resource_listing.sh <service> <region>
Replace <service>
with the desired AWS service (e.g., ec2, rds, etc.) and <region>
with the AWS region (e.g., us-west-2, us-east-1, etc.).
To list all EC2 instances in the us-west-2 region, you would run:
./aws_resource_listing.sh ec2 us-west-2
The script leverages AWS CLI commands to query specific services based on the user inputs for service type and AWS region. Upon execution, the script will:
- Check if the required AWS CLI is installed and configured.
- Parse command-line arguments for the service and region.
- Execute the appropriate AWS CLI command to list the resources for the specified service.
- Output the results in a user-friendly format.
- Clone the repository or download the script.
- Ensure Python 3 is installed on your system.
- Install any required Python dependencies, if any.
- Run the Python script using the following command:
python aws_resource_list.py <aws_region> <aws_service>
Replace <aws_region>
with the AWS region (e.g., us-west-2, us-east-1, etc.), and <aws_service>
with the AWS service to query (e.g., ec2, rds, etc.).
To list all EC2 instances in the us-west-2 region, you would run:
python aws_resource_list.py us-west-2 ec2
The Python script works similarly to the Bash script but uses the subprocess
module to interact with the AWS CLI. When executed, the Python script:
- Verifies if the AWS CLI is installed and configured.
- Takes command-line arguments for the service and region.
- Executes the appropriate AWS CLI command using the
subprocess
module. - Prints the result of the AWS CLI command to the console in a user-friendly format.
To install the necessary tools for the Python script:
- Install Python 3.x, if not already installed. You can download it from here.
- Ensure the AWS CLI is installed and configured.
- Both Scripts Require AWS CLI: Ensure that the AWS CLI is installed and configured with appropriate access credentials before running the script.
- Service Name: When providing the service name, ensure it matches the supported services exactly as listed above (case-insensitive). For example, use
ec2
for EC2 instances,s3
for S3 buckets, etc.
-
AWS CLI Not Installed: If you receive an error indicating that AWS CLI is not installed, follow the installation instructions above.
-
AWS CLI Not Configured: Ensure that you have set up your AWS credentials using
aws configure
. You can check the configuration by running:aws configure list