# #Day7 Reporting of AWS resource usage using Shell Scripting #project-I

**Introduction:**

In the dynamic landscape of cloud computing, managing AWS resources efficiently is crucial for businesses and developers. Keeping track of S3 buckets, EC2 instances, Lambda functions, and IAM users is essential for optimization and security. In this blog post, we will explore an automated solution for AWS resource tracking using a Bash script and cron jobs.

Note:

1. **Ensure** `jq` **is Installed:** The script uses `jq` to process JSON output from AWS CLI. Make sure `jq` is installed on your system. If it's not installed, you can install it using a package manager like `apt` (for Ubuntu) or `yum` (for Amazon Linux).
    
    ```plaintext
    bashCopy code# For Ubuntu
    sudo apt-get install jq
    
    # For Amazon Linux
    sudo yum install jq
    ```
    
    With `jq`, you can perform various operations on JSON documents, making it a powerful tool for processing JSON data in shell scripts, including Bash scripts.
    
2. **Verify AWS CLI Configuration:** Ensure that the AWS CLI is configured correctly with the necessary credentials and default region. You can verify this by running `aws configure` and provide the required information.
    

"If you want to learn how to configure AWS CLI, please watch my previous blog."

**1 Bash Script (**`aws_resource_tracker.sh`**):**

* **Purpose:** This is the main script of the project written in Bash.
    
* **Functionality:**
    
    * Lists S3 buckets using `aws s3 ls` and appends the output to the `resourceTracker` file.
        
    * Lists EC2 instances using `aws ec2 describe-instances` and `jq` for JSON parsing. Appends instance IDs to the `resourceTracker` file.
        
    * Lists Lambda functions using `aws lambda list-functions` and appends the output to the `resourceTracker` file.
        
    * Lists IAM users using `aws iam list-users` and appends the output to the `resourceTracker` file.
        
* **Usage:** The script is scheduled to run periodically using cron jobs
    
    "I have completed the practical part step by step, which can be helpful."
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695742719778/c87e5446-3010-4490-8ff0-4852e18158ae.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695743674636/38ac1c21-5f26-4e7f-9502-e2976a857b54.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696072011843/d011b6f0-b0dd-4d59-a35a-e2ef3db415ee.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696073084675/9c3670e3-864c-4ed7-b9b3-f356c2508693.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696073158425/8860c84c-8411-4ad8-94ce-1dd4299f0462.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696072976279/3a0b6dac-ae99-4688-8c0d-9aa19e1498d3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696073016765/9206cbde-8b8b-494f-8036-db19fde0e186.png align="center")

**Cron Job:**

* **Purpose:** Automates the execution of the Bash script at specific intervals.
    
* **Functionality:** Runs the Bash script at 2:00 AM every day.
    
* **Configuration:** Set up using `crontab -e` and added the following line:
    
* **Note:** The `chmod +x` command ensures that the script has the necessary execute permissions to be run by the cron job.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696075751652/979b8356-27a4-4b60-83f2-4d1559f99478.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696226276226/3ba71898-3754-41bb-99ce-63afb4164856.png align="center")

### **Project Workflow:**

1. **Cron Job Execution (Every day at 2:00 AM):**
    
    * The cron job triggers the `aws_resource_tracker.sh` script at the specified time.
        
2. **Bash Script Execution:**
    
    * The Bash script runs the AWS CLI commands to gather information about different AWS resources.
        
3. **Data Collection and Storage:**
    
    * The script collects data about S3 buckets, EC2 instances, Lambda functions, and IAM users.
        
    * Each type of resource data is appended to the `resourceTracker` file.
        
4. **Resource Tracking:**
    
    * Over time, the `resourceTracker` file accumulates information about the AWS resources.
        

This project provides a simple and automated way to track various AWS resources regularly. It can serve as a foundation for more complex AWS resource tracking and analysis systems. Remember to continuously monitor the script's execution to ensure it operates as intended and to address any issues promptly.
