-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist_resources.sh
More file actions
executable file
·117 lines (110 loc) · 3.33 KB
/
list_resources.sh
File metadata and controls
executable file
·117 lines (110 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
###############################################################################
# Author: Dushyanth Bandaru
# 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