AWS project Using Shell Scripting for Tracking AWS Resources
In this project we will be monitoring Basic AWS resources like Listing s3 Buckets, AWS EC2 instances, AWS Lamda Functions, AWS IAM Users
Table of contents
1) Connect to AWS EC2 instance
Visit this blog,how to Create AWS EC2 instance for Ubuntu.
Link : https://vijayblogs.hashnode.dev/how-to-create-a-aws-virtual-machine-aws-ec2-instance
```bash 21/05/2023 11:11.43 /home/mobaxterm chmod 600 C:/Users/vijay/Downloads
21/05/2023 11:18.13 /home/mobaxterm ssh -i C:/Users/vijay/Downloads/test11.pem ubuntu@
3. Here I am using Bash Shell
```bash
ubuntu@ip-172-31-28-28:~$ bash
Install AWS CLI . Refer my Blog
Link : https://vijayblogs.hashnode.dev/how-to-create-a-aws-virtual-machine-aws-ec2-instance
Now configure AWS credentials to connect with AWS.
aws configure
Enter your Access Key Id,Secret Access Key Default region name and Output Format.
Now we will start writing our script to track AWS resources. We will name it as aws_resource_tracker_.sh
vim aws_resource_tracker_.sh
Write the Script in VIM Editor
```bash #!/bn/bash
######################
Author:Vijay
#Date: 20th- May # #Version :v1 # #This Script will report AWS resource Usage ################## set -x #AWS S3 #AWS EC2 #AWS Lamda #AWS IAM Users
#List S3 Buckets aws s3 ls
#List EC2 Instances aws ec2 describe-instances
#List AWS Lambda Functions aws lambda list-functions
#List IAM USer aws iam list-users
Here set -x will run the script in debug mode
7. Now we run this script and we will get to know about the 1)List of S3 Buckets
2)List of EC2 Instances 3) List of AWS Lambda Functions 4) List of IAM Users
```bash
chmod 777 aws_resource_tracker_.sh
./aws_resource_tracker_.sh | more
This will run the script in a readable format.
OUTPUT:
If we only want the Instance ID we can use JSON Parser as this script output is in JSON. We can make script changes using VIM and replace EC2 instance command with following
aws ec2 describe-instances | jq '.Reservations[].Instances[].InstanceId[]'
This is how we track our resources of AWS using BASH scripting and AWS CLI
Resources I followed:
Youtube Video by Abhishek Verramala
https://www.youtube.com/watch?v=gx5E47R9fGk&list=PLdpzxOOAlwvIKMhk8WhzN1pYoJ1YU8Csa&index=9