My DevOps Journey: Week 4 – Automating with Shell Scripts and Exploring AWS CLI

My DevOps Journey: Week 4 – Automating with Shell Scripts and Exploring AWS CLI

This week, my DevOps journey took a significant step forward as I explored three major topics: Shell Scripting, AWS CLI, and scripting to display AWS resource usage. Here's a breakdown of what I learned:


1. Shell Scripting: The Foundation of Automation

This week, I deep-dived into Shell Scripting and its role in automation and system management. Here’s what I covered:

  • What is Shell Scripting? A way to automate repetitive tasks in Linux-based systems.

  • Basic Operations: Writing, reading, and running shell scripts.

  • What is Shebang (#!) and its significance in specifying the script interpreter.

  • Exploring Examples: Hands-on scripting to perform tasks like file handling, user input, and conditional statements.

  • Standards for Writing Scripts: Best practices to make scripts readable, reusable, and error-free.

  • DevOps Connection: Understanding how scripting simplifies configuration, monitoring, and deployments.

  • Error Handling: Using set -e, set -o pipefail, and other techniques.

  • Networking Tools: Using tools like curl and wget within scripts for remote server interaction.

  • Advanced Topics: Implementing logic with if-else statements, loops, file reading, and passing parameters.

For a detailed explanation of each topic, check out my blog:
👉 Shell Scripting Basics and Beyond

📸 :


2. Exploring AWS Console and CLI

This week, I explored various aspects of AWS and its CLI, focusing on essential topics:

What is AWS EC2?

Amazon EC2 (Elastic Compute Cloud) provides scalable compute capacity in the cloud.

  • Ways to Connect EC2 Instances: Using SSH, AWS Management Console, or AWS CLI.

  • Connecting via Terminal: Setting up SSH keys, logging in securely, and managing instances directly from the terminal.

What is AWS CLI?

AWS CLI is a command-line interface to interact with AWS services.

  • How to Configure AWS CLI:

      aws configure
    

    This command allows you to set your Access Key, Secret Key, Default Region, and Output Format (e.g., JSON).
    Example:

      AWS Access Key ID: [Your Access Key]  
      AWS Secret Access Key: [Your Secret Key]  
      Default region name: us-west-2  
      Default output format: json
    

    Advantages: It provides automation, faster resource management, and simplified workflows.

AWS CloudFormation Templates:

Automates resource provisioning using YAML/JSON templates. It's like Infrastructure as Code (IaC) for AWS.

What is boto3?

A Python library to interact with AWS resources programmatically. It’s handy for tasks requiring deeper automation.

📸 Image Suggestion:

  • Example of EC2 instance details fetched using AWS CLI commands.


3. Shell Script to Display AWS Resource Usage

This week, I combined my shell scripting and AWS CLI knowledge to create a script that reports the usage of various AWS resources like S3, EC2, Lambda, and IAM. Here’s the script:

Challenges Faced:

  1. Incorrect EC2 Region:

    • Initially, I wasn’t able to retrieve any EC2 instance details because the default region was incorrect.

    • Solution: Specify the region explicitly using:

        aws ec2 describe-instances --region us-west-2
      

      Update the default region with:

        aws configure set region us-west-2
      
  2. Fetching Necessary EC2 Information:

    • Solution: Use jq, a JSON parser, to extract specific details from the EC2 response.

Why is This Useful?

This script provides a quick overview of AWS resource usage, which is essential for monitoring and cost management in a DevOps workflow.

📸


Key Takeaways from Week 4

  • Learned Shell Scripting and its applications in automation.

  • Explored AWS Console and CLI, gaining hands-on experience in EC2, CloudFormation, and boto3.

  • Successfully integrated shell scripting with AWS CLI to automate resource reporting.

Next Week Goals 🎯

For Week 5, my plan includes:

  • 🚀 Exploring AWS CLI in Depth: Understanding more advanced commands and configurations.

  • ✍️ Writing Shell Scripts to Communicate with AWS Console: Automating tasks like launching instances, managing storage, and more.

  • 🛠️ Real-Time Shell Scripting Project: Working on a small project to showcase how shell scripting can solve real-world DevOps problems.

Excited to dive deeper into the DevOps journey! Stay tuned! 😊

If you found this blog helpful and want to follow along with my DevOps journey, feel free to subscribe and connect with me on LinkedIn and X.

Let’s grow together! 🚀😇