Skip to main content

Command Palette

Search for a command to run...

AWS Resource Tracking Shell Script

Published
2 min read
A

DevOps | Cloud Practitioner | AWS | GIT | Kubernetes | Terraform | ArgoCD | Gitlab

Description

This Bash script tracks various AWS resources and saves the output to a file named resourceInfo.txt. It helps DevOps engineers and system administrators keep an inventory of their AWS resources, including S3 buckets, EC2 instances, Lambda functions, and IAM users.


Features

  • Lists all S3 buckets.

  • Describes all EC2 instances.

  • Lists all Lambda functions.

  • Prints IAM user IDs using jq for JSON parsing.

  • Outputs all resource information to resourceInfo.txt.


Bash Script:

#/bin/bash
#
##Author: Amit
##Date: 5th Jan
##Version: V1
##This script will report AWS resource tracking
#########################
#
set -x # help to run in debug mode
#
##list s3 bucket AWS
echo "print list of s3 bucket"
aws s3 ls > resourceInfo.txt
#
##list ec2 instance
echo "print ec2 instance"
aws ec2 describe-instances >> resourceInfo.txt
#
##list lambda
echo "listing lambda functions"
aws lambda list-functions >> resourceInfo.txt
#
##list IAM USERS
echo "printing IAM users"
aws iam list-users | jq '.Users[].UserId' >> resourceInfo.txt

Prerequisites

Before running this script, ensure the following:

  1. AWS CLI
    Install and configure the AWS CLI:

     aws configure
    
  2. jq
    Install the jq tool for JSON parsing:

    • On Ubuntu/Debian:

        sudo apt update
        sudo apt install jq
      
    • On RHEL/CentOS:

        sudo yum install jq
      
  3. Bash Shell
    The script is designed to run in a Bash environment.


Usage

  1. Clone this repository:

     git clone https://github.com/your-username/aws-resource-tracking.git
     cd aws-resource-tracking
    
  2. Make the script executable:

     chmod +x aws_resource_tracking.sh
    
  3. Run the script:

     ./aws_resource_tracking.sh
    
  4. View the resource information:

     cat resourceInfo.txt
    

Output

The script generates a file named resourceInfo.txt containing information about:

  • S3 buckets

  • EC2 instances

  • Lambda functions

  • IAM users


Debugging

The script runs in debug mode (set -x) to display each command as it's executed. You can disable debug mode by removing or commenting out the set -x line.


Notes

  • Ensure your AWS CLI credentials have the necessary permissions to access the resources.

  • If jq is not installed, you can modify the script to use grep and awk as an alternative.


Author

Amit
Date: January 5th
Version: V1


Feel free to customize this README based on your needs!

More from this blog

DevOps Projects and Blog

69 posts