Pre-Requisites:
AWS CLI
Access key
Installation of prerequisites:
๐ง AWS CLI:
On Ubuntu, use the following command:
sudo apt install awscli
Create and configure access key:
-
Click on your AWS account name in the top right corner.
Select "Security Credentials".
Scroll and find the access key, then click "Create access key".
-
-
aws configure
Enter the access key ID and secret when prompted.
-
Script:
#!/bin/bash
###########################################################################
# ๐ ๏ธ This script tracks resources in our AWS account ๐ ๏ธ #
###########################################################################
##### List IAM Users #####
echo "IAM users are:" > resources.txt
echo "Before JSON Parsing" >> resources.txt
aws iam list-users >> resources.txt
echo "After JSON Parsing by filtering with username alone" >> resources.txt
aws iam list-users | jq '.Users[].UserName' >> resources.txt
##### List EC2 Instances #####
echo "EC2 Instances that we have:" >> resources.txt
aws ec2 describe-instances | jq '.Reservations[].Instances[].Tags[].Value' >> resources.txt
##### List IAM Group #####
echo "IAM Groups are:" >> resources.txt
aws iam list-groups >> resources.txt
##### List S3 Bucket #####
echo "S3 buckets are:" >> resources.txt
aws s3 ls >> resources.txt
Usage:
Make a .sh filetouch aws_resource_tracker.sh chmod +x aws_resource_tracker.sh
Open the script file: vim aws_resource_tracker.sh
Paste the script and save it.
Execute the script: ./aws_resource_tracker.sh
Output: ๐ resources.txt:
IAM users are:
Before JSON Parsing
... [IAM user details]
After JSON Parsing by filtering with username alone
... [Filtered usernames]
EC2 Instances that we have:
... [EC2 instance details]
IAM Groups are:
... [IAM group details]
S3 buckets are:
... [S3 bucket details]
Automate Using CRON JOB:
Open crontab file:
sudo nano /etc/crontab
Add the job to run the script daily at 16:40 (4:40 pm):
40 16 * * * ubuntu bash /home/ubuntu/aws_resource_tracker.sh
ย