Shell scripting - usage of AWS resources

Shell scripting - usage of AWS resources

A script to report the usage of AWS in your projects.

Using this shell script what you do is you create a file and this file will have all of this resource usage.we will monitor the resource for this resources like AWS ec2 instance, s3 bucket,lambda function,IAM users etc lets say you have to give this report to your manager or supply this information to a reporting dashboard. Then this shell script can be integrated with cronjob and it will automatically execute this shell script for you.

NOTE: Make sure that you have to install AWS CLI on your computer.

Step 1: You have to open the terminal and create a file:

vim aws-resource-tracker.sh

Step 2: you have to write a shell script.

#!/usr/bin/bash

############
#Author: shreyash
#Date: 11-07-23

#This script will report the AWS resource usage
######################

set -x

# AWS S3
# AWS EC2
# AWS Lambda
# AWS IAM users

# list S3 bucket
echo "print list of s3 bucket"
aws s3 ls


# list EC2 Instances
echo "print list of ec2 instance"
aws ec2 describe-instances

# list lambda
echo "print list of lambda"
aws lambda list-functions

# list IAM users
echo "print list of iam usersu"
aws iam list-users
~

Step 3 : You have to make this file executable using this command.

chmod 777 aws-resource-tracker.sh

Step 4: You have to run this script using this command.

./aws-resource-tracker.sh

Step 5 : You can use this command if you want only a ec2 instance id.

aws ec2 describe-instances | jq '.Reservations[].Instances[].InstanceId'