Created
August 14, 2024 13:50
-
Star
(59)
You must be signed in to star a gist -
Fork
(191)
You must be signed in to fork a gist
-
-
Save iam-veeramalla/24ba6d64ffaffb925e7d28166266ce49 to your computer and use it in GitHub Desktop.
Script to automate the process of listing all the resources in an AWS account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ############################################################################### | |
| # Author: Abhishek Veeramalla | |
| # Version: v0.0.1 | |
| # Script to automate the process of listing all the resources in an AWS account | |
| # | |
| # Below are the services that are supported by this script: | |
| # 1. EC2 | |
| # 2. RDS | |
| # 3. S3 | |
| # 4. CloudFront | |
| # 5. VPC | |
| # 6. IAM | |
| # 7. Route53 | |
| # 8. CloudWatch | |
| # 9. CloudFormation | |
| # 10. Lambda | |
| # 11. SNS | |
| # 12. SQS | |
| # 13. DynamoDB | |
| # 14. VPC | |
| # 15. EBS | |
| # | |
| # The script will prompt the user to enter the AWS region and the service for which the resources need to be listed. | |
| # | |
| # Usage: ./aws_resource_list.sh <aws_region> <aws_service> | |
| # Example: ./aws_resource_list.sh us-east-1 ec2 | |
| ############################################################################# | |
| # Check if the required number of arguments are passed | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: ./aws_resource_list.sh <aws_region> <aws_service>" | |
| echo "Example: ./aws_resource_list.sh us-east-1 ec2" | |
| exit 1 | |
| fi | |
| # Assign the arguments to variables and convert the service to lowercase | |
| aws_region=$1 | |
| aws_service=$2 | |
| # Check if the AWS CLI is installed | |
| if ! command -v aws &> /dev/null; then | |
| echo "AWS CLI is not installed. Please install the AWS CLI and try again." | |
| exit 1 | |
| fi | |
| # Check if the AWS CLI is configured | |
| if [ ! -d ~/.aws ]; then | |
| echo "AWS CLI is not configured. Please configure the AWS CLI and try again." | |
| exit 1 | |
| fi | |
| # List the resources based on the service | |
| case $aws_service in | |
| ec2) | |
| echo "Listing EC2 Instances in $aws_region" | |
| aws ec2 describe-instances --region $aws_region | |
| ;; | |
| rds) | |
| echo "Listing RDS Instances in $aws_region" | |
| aws rds describe-db-instances --region $aws_region | |
| ;; | |
| s3) | |
| echo "Listing S3 Buckets in $aws_region" | |
| aws s3api list-buckets --region $aws_region | |
| ;; | |
| cloudfront) | |
| echo "Listing CloudFront Distributions in $aws_region" | |
| aws cloudfront list-distributions --region $aws_region | |
| ;; | |
| vpc) | |
| echo "Listing VPCs in $aws_region" | |
| aws ec2 describe-vpcs --region $aws_region | |
| ;; | |
| iam) | |
| echo "Listing IAM Users in $aws_region" | |
| aws iam list-users --region $aws_region | |
| ;; | |
| route5) | |
| echo "Listing Route53 Hosted Zones in $aws_region" | |
| aws route53 list-hosted-zones --region $aws_region | |
| ;; | |
| cloudwatch) | |
| echo "Listing CloudWatch Alarms in $aws_region" | |
| aws cloudwatch describe-alarms --region $aws_region | |
| ;; | |
| cloudformation) | |
| echo "Listing CloudFormation Stacks in $aws_region" | |
| aws cloudformation describe-stacks --region $aws_region | |
| ;; | |
| lambda) | |
| echo "Listing Lambda Functions in $aws_region" | |
| aws lambda list-functions --region $aws_region | |
| ;; | |
| sns) | |
| echo "Listing SNS Topics in $aws_region" | |
| aws sns list-topics --region $aws_region | |
| ;; | |
| sqs) | |
| echo "Listing SQS Queues in $aws_region" | |
| aws sqs list-queues --region $aws_region | |
| ;; | |
| dynamodb) | |
| echo "Listing DynamoDB Tables in $aws_region" | |
| aws dynamodb list-tables --region $aws_region | |
| ;; | |
| ebs) | |
| echo "Listing EBS Volumes in $aws_region" | |
| aws ec2 describe-volumes --region $aws_region | |
| ;; | |
| *) | |
| echo "Invalid service. Please enter a valid service." | |
| exit 1 | |
| ;; | |
| esac |
line 41: Aws_service is not converted to lower case . aws_service=$(echo "$2" | tr '[:upper:]' '[:lower:]') this should solve the issue
right
correct
Check my repo https://github.com/SanthoshKumar1903/Shell-Scripting-Projects
To make it lower case change the code as
aws_region=${1,,}
aws_service=${2,,}
This make the text to lowercase.
Also make sure to fix the spelling route53 in the case.
I created a Bash script that lists all major Google Cloud Platform (GCP) resources in a project using the gcloud CLI — adapted from an AWS resource listing script.
Check it out here: https://github.com/MDevaWilliams/gcp-resource-listing
and feel free to fork or contribute!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 41: Aws_service is not converted to lower case .
aws_service=$(echo "$2" | tr '[:upper:]' '[:lower:]')
this should solve the issue