top of page
Writer's pictureRitika Malhotra

🌻AWS Project Using Shell Scripting for DevOps Engineers 🌻

Write a shell script to report the usage of AWS resources in your project



Objective — An Organization is using an EC2 Instance, S3 Bucket, Lambda Function, and IAM for users. Our goal is that every day at a certain time, we need to report the usage of these resources in the project to our manager.


SolutionWe will write a shell script to execute this task. The shell script can be integrated with a CronJob. So, the Linux project will wait for the scheduled time and automatically execute the script. This task can be accomplished in several ways, however here I have used Shell Scripting and AWS CLI for the same.


Here are the steps we need to follow:-

Step 1 Create an AWS EC2 T2 Micro Instance using Ubuntu as OS, you can use an existing key pair or create a new one. Enable HTTP and HTTPS settings and finally connect to the instance using your browser.

Step 2 — Update the packages using $ sudo apt-get update

Step 3 — Then, install the AWS CLI using $ sudo apt-get install aws cli. The AWS Command Line Interface is an open-source tool that enables you to interact with AWS services using commands in your command-line shell. Refer to this URL for more installation details. https://docs.aws.amazon.co/cli/latest/userguide/getting-started-install.html This is how it will look. It says that AWS cli is installed.


Step 4 — We need to configure credentials to be able to communicate with AWS CLI. To achieve this, we need to provide the AWS Access Key and Secret Access Key which can be found on your AWS Console. Run, the AWS configure command and enter the details. Remember, to save this in your digital wallet as this is confidential information.



Step 5 — Next, using the VIM Editor we will create an aws_Resource_tracker.sh and input our commands. We can use the detailed CLI reference sheet which provides a detailed interface for interacting with all parts of AWS. Refer to this URL for more details



Step 6 — Once you come out of the VIM Editor, type in #chmod 777 aws_resource_tracker.sh to grant it permission. Then to execute the script, we need to enter # ./aws_resource_tracker.sh

The output would look like this



Hope, you will be able to run this simple bash script. If you need any further details, please feel free to comment below and I will get back to you.


 

If you liked this, please give your claps and follow me for more DevOps projects. Thank you! 🙏



550 views

Recent Posts

See All
bottom of page