In the dynamic world of cloud computing, managing resources across an AWS environment can be a daunting task. With numerous services spread across different regions, keeping track of everything manually is not only time-consuming but also prone to error. To address this challenge, I’ve developed a simple yet powerful shell script that automates the process of listing all resources in an AWS account.
This script provides a quick and efficient way to gather detailed information about your AWS infrastructure, covering a wide range of services like EC2, RDS, S3, and more. Whether you’re a cloud architect responsible for multiple environments or a developer managing a single account, this tool can significantly simplify your workflow, ensuring that you always have an up-to-date inventory of your cloud resources.
In this article, I’ll walk you through the development and functionality of this script, showcasing how automation can enhance your cloud management strategy.
The focus of this project is to provide a solution for listing resources of a user
on AWS in an automated way, and basically could be used to perform cron job as the case may suit the user and the need in the line of automation.
Supported Services
The script currently supports listing resources for the following AWS services:
- EC2
- RDS
- S3
- CloudFront
- VPC
- IAM
- Route53
- CloudWatch
- CloudFormation
- Lambda
- SNS
- SQS
- DynamoDB
- EBS
Features
- Multi-Region Support: The script can query resources across multiple AWS regions.
- Service Coverage: Lists resources from major AWS services such as EC2, S3, RDS, Lambda, and more.
- Output Formats: Results can be outputted in plain text or saved to a file for easy integration with other tools.
- Error Handling: Includes basic error handling to manage API rate limits and service-specific issues.
Prerequisites
Before running the script, ensure you have the following:
AWS CLI: Installed and configured with the necessary permissions to query AWS resources.
Bash Shell: The script is written for Unix-like environments (Linux, macOS, WSL on Windows).
IAM Permissions: The IAM user or role running the script should have read-only permissions to all AWS services being queried.
Setup
STEPS
- clone the Repository:
https://github.com/Aymogul/Aws-resource-script.git
- Install AWS CLI on the instance
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
- Configure AWS CLI: Ensure your AWS CLI is configured with the necessary credentials and default region
aws configure
Input your:
Access key
Secret Key
Regon
Output as JSON
- Make script Executable: Give execution permission to the script
chmod +x aws_resource_list.sh
or
chmod 771 aws_resource_list.sh
Usage
- Run the script This can be executed directly from the command line after you have logged into an EC2 via ssh or puTTY
./aws_resource_list.sh <aws_region> <aws_service>
example usage
./aws_resource_list.sh us-east-1 ec2
- Output:
This script will run and the output of the AWS resource list will be outputed to
aws_resources.txt
.
./_aws_resource_list.sh > aws_resources.txt
- Customization of Regions and other Variables: By default, the script will query resources in all regions. You can edit the regions variable in the script to specify particular regions:
regions="us-east-1"
This command will list all EC2 instances in the us-east-1
region.
- Valid AWS Services:
The script supports various services like ec2
, rds
, s3
, cloudfront
, vpc
, iam
, route53
, cloudwatch
, cloudformation
, lambda
, sns
, sqs
, dynamodb
, and ebs
.
Error Handling
AWS CLI Not Installed: The script checks if AWS CLI is installed and configured. If not, it will prompt the user to install and configure it.
Invalid Service: If an unsupported service is specified, the script will return an error message.
Customization
Additional Services: You can modify the script to include additional AWS services by adding new cases to the case block.
Output Format: The script can be enhanced to format output in different ways (e.g., JSON, CSV) depending on your requirements.
Contribution
Contributions are welcome! If you have improvements or additional features, feel free to fork the repository and submit a pull request.
Top comments (0)