This project automates the process of listing active AWS resources for specific services in a given AWS region using a shell script.
The project focuses on automating AWS resource management using shell scripting. The primary goal is to create a shell script that connects to AWS and lists active resources based on user-defined parameters. This automation aids in monitoring and managing cloud resources efficiently
The script:
- Connects to AWS using AWS CLI
- Accepts two arguments:
regionandservice - Lists only active resources for the specified AWS service
- Supports only allowed services defined in the script
- Implements best practices for shell scripting and security
Follow these steps to use the script on an Ubuntu-based EC2 instance:
-
Launch an EC2 Instance
- Use the AWS Console or CLI to launch an Ubuntu EC2 instance.
- Ensure the instance has an IAM role with permissions to list AWS resources, or configure credentials manually.
-
Connect to Your EC2 Instance
ssh -i <your-key.pem> ubuntu@<ec2-public-dns>
-
Update the System (Optional but Recommended)
sudo apt update && sudo apt upgrade -y -
Install AWS CLI (if not already installed)
sudo apt install awscli -y aws --version
-
Configure AWS CLI (if not using an IAM role)
aws configure
- Enter your AWS Access Key, Secret Key, default region, and output format.
-
Transfer the Script to the EC2 Instance
- You can use
scpfrom your local machine:scp -i <your-key.pem> aws_resource_list.sh ubuntu@<ec2-public-dns>:~/
- Or, create the script directly on the instance using a text editor like
nanoorvim.
- You can use
-
Make the Script Executable
chmod +x aws_resource_list.sh
-
Run the Script
./aws_resource_list.sh <aws_region> <aws_service>
- Example:
./aws_resource_list.sh us-east-1 ec2
- Example:
By default, the script supports these services:
ec2– List running EC2 instancess3– List S3 bucketsebs– List active EBS volumesrds– List RDS instancesdynamodb– List DynamoDB tablessns– List SNS topicslambda– List Lambda functionsvpc– List VPCsefs– List EFS file systemseks– List EKS clusterscloudformation– List CloudFormation stacksiam– List IAM users and roleselb– List Elastic Load Balancers
(You can add/remove services in the script as per your organization’s usage.)
Before running the script, ensure you have:
- AWS CLI Installed
Installation Guide
Check installation:aws --version
- AWS credentials with permissions to list resources for the desired services.
- To grant all the access
chmod +x aws_resource_list.sh- For specific Access (user, groups all the access, others with only execute access)
chmod 771 aws_resource_list.sh./aws_resource_list.sh <aws_region> <aws_service><aws_region>: The AWS region code (e.g.,us-east-1,eu-west-1)<aws_service>: The AWS service to list (see supported services above)
./aws_resource_list.sh us-east-1 ec2This will list all EC2 instances in the us-east-1 region.
List S3 Buckets:
./aws_resource_list.sh us-east-1 s3Output:
Listing S3 buckets in region us-east-1...
[
"my-bucket-1",
"my-bucket-2"
]
Resource listing completed for service: s3 in region: us-east-1
List Lambda Functions:
./aws_resource_list.sh eu-west-1 lambdaOutput:
Listing Lambda functions in region eu-west-1...
[
[
"my-function",
"python3.8",
"2025-08-11T12:34:56.000+0000"
]
]
Resource listing completed for service: lambda in region: eu-west-1
The script performs several validation checks before listing AWS resources:
-
Argument Validation
- Ensures exactly two arguments are provided:
<aws_region>and<aws_service>. - If not, it displays usage instructions and exits.
- Ensures exactly two arguments are provided:
-
AWS CLI Installation Check
- Verifies if the AWS CLI is installed on your system.
- If not found, it prompts you to install the AWS CLI and exits.
-
AWS CLI Configuration Check
- Checks if the AWS CLI is configured with valid credentials.
- If not configured, it prompts you to run
aws configureand exits.
-
AWS Region Validation
- Validates the provided AWS region.
- If the region is invalid, it displays an error and exits.
-
AWS Service Validation
- Checks if the provided service is among the supported services.
- If not, it lists the valid services and exits.
See the images below for sample validation outputs:
- The script checks for AWS CLI installation and configuration.
- Only valid AWS regions and supported services are accepted.
- Output is displayed in JSON format for easy parsing.
- You can add or remove supported services by editing the script.
Rubeena Shaik




