Write your  First  Shell-Script to Automate Stuff on AWS.

Write your First Shell-Script to Automate Stuff on AWS.

A Script to Report Usage of AWS Resources.

What is shell scripting and why is it important in DevOps?

Shell scripting is the process of writing scripts to automate tasks in a Unix-like operating system environment. It's crucial in DevOps for automating deployments, configuring infrastructure, and managing environments. Shell scripts facilitate continuous integration, delivery, and deployment processes, enhancing efficiency and reducing manual effort in DevOps practices.

Script to report usage of AWS ,Why is it important?

This script reports usage of AWS resources i.e effectively managing and optimizing cloud infrastructure, enhancing operational efficiency, and ensuring the security and reliability of AWS environments.

Commands used in this Script:

A. Writing down the Script:

  1. We need create a file using vim editor.

    1. To write content inside it use "esc key and i".

    2. To save content and exit from editor use "esc key and :wq".

  1. Copy down the script into your editor.
#!/bin/bash
###################
# Name:Script to report the usage of AWS Resources.
# Author:Venkat
# Version:1
###################
set -x #debug mode
# In This Script we will list the the usage of AWS Resources like:
#AWS S3
#AWS EC2
#AWS Lambda
#AWS IAM

# commands
aws s3 ls
aws ec2 describe-instances | jq 'Reservations[].Instances[].InstanceId'
aws lambda-functions
aws users list-users
  1. You need to change the permissions of the file.
chmod 777 my-first-script.sh
  1. Execute the script using the command.
./my-first-script.sh
  1. Now you need to configure AWS, At first it says to download "AWS-CLI" don't go ahead and start downloading AWS-CLI ,It is good practice to update your machine first using:
sudo apt update
  1. And then go ahead by installing AWS-CLI by using:
sudo apt install awscli

B. Configuring AWS :

  1. Now when you write AWS, it responds like this.

  1. Now we need to configure our AWS , for that first we need to create Access keys:

    Click on Profile which is at top right side > Security Credentials > Access Keys > Create Access keys and your access key swill be created.

  1. I am not sharing my Access keys for security reasons, and after you need to configure your aws by using :
aws configure

4.It will ask you AWS Access key ID , AWS Secret Access Key , Default region name and Default output format.

AWS Access Key IDCopy the access key you created earlier.
AWS Secret Access keySecret key will be beside of access key copy it and paste it here.
Default region NameSpecify your region
Default output formatjson.

  1. Now when you execute the script, it will give you error that "jq "is not available , and install jq using the command
sudo apt install jq
  1. At last execute the script , you will get the response.

You will get response of AWS S3, AWS Ec2 Instance ID, AWS Lambda, AWS IAM Users.

If you find it useful , for more interesting content Follow me.

Thank You.