๐ AWS Usage Report Script ๐
Summary
This script uses the AWS CLI to retrieve information about various AWS resources like EC2 instances, S3 buckets, IAM users and Lambda functions. It then presents the data in a JSON format, giving you an overview of your AWS resource usage. Remember to install the AWS CLI and configure it with the necessary credentials before running the script.
Also, install the following
sudo apt-get install jq
sudo apt install unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
steps for writing code and executing it
Step 1: Go to aws cli
step2: create a file eg: vi usage.sh
step3: write the code as given and save it by typing the ESC button after that type wq!
#!/bin/bash
####################################################
# Author: vishwajit kumar #
# Date: 24/07/2023 #
# Version: v1 #
# This scripts will report the AWS resource usages #
####################################################
set -x
# AWS s3 buckets
echo "print the list of s3 buckets"
aws s3 ls
# AWS ec2 instance
echo "print the list of ec2 instance"
aws ec2 describe-instances | jq '.Reservations[].Instances[].InstanceId'
#AWS list of lambda
echo "print the list of lambda function"
aws lambda list-functions
#AWS IAM list
echo "print the list of IAM role "
aws iam list-users
step 4: give permission to the file
chmod 777 usage.sh
step 5: run the command
./usage.sh
you can see the output below
ubuntu@ip-172-31-25-32:~$ ./usages.sh
+ echo 'print the list of s3 buckets'
print the list of s3 buckets
+ aws s3 ls
+ echo 'print the list of ec2 instance'
print the list of ec2 instance
+ jq '.Reservations[].Instances[].InstanceId'
+ aws ec2 describe-instances
"i-06a88c90389aadcd9"
"i-071a886b7503ed7f4"
+ echo 'print the list of lambda function'
print the list of lambda function
+ aws lambda list-functions
{
"Functions": []
}
+ echo 'print the list of IAM role '
print the list of IAM role
+ aws iam list-users
{
"Users": [
{
"Path": "/",
"UserName": "pluralsight-be6548d9",
"UserId": "AIDAQEPBX4434K72VPK7R",
"Arn": "arn:aws:iam::009600231223:user/pluralsight-be6548d9",
"CreateDate": "2023-07-24T08:28:28+00:00",
"PasswordLastUsed": "2023-07-24T08:35:46+00:00"
}
]
}
