<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: benny fmo</title>
    <description>The latest articles on DEV Community by benny fmo (@bennyfmo_237).</description>
    <link>https://dev.to/bennyfmo_237</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1922869%2F2e87ee62-92f0-4626-aa63-709f05d4e1c9.jpg</url>
      <title>DEV Community: benny fmo</title>
      <link>https://dev.to/bennyfmo_237</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bennyfmo_237"/>
    <language>en</language>
    <item>
      <title>Step-by-Step Guide to EC2 Auto Scaling and Load Balancing on AWS</title>
      <dc:creator>benny fmo</dc:creator>
      <pubDate>Fri, 11 Oct 2024 08:52:56 +0000</pubDate>
      <link>https://dev.to/bennyfmo_237/step-by-step-guide-to-ec2-auto-scaling-and-load-balancing-on-aws-473c</link>
      <guid>https://dev.to/bennyfmo_237/step-by-step-guide-to-ec2-auto-scaling-and-load-balancing-on-aws-473c</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As businesses and applications grow, the demand for computing power fluctuates. Traditionally, managing this involved investing in expensive hardware and requiring manual interventions to scale. However, with cloud computing, you now have the ability to dynamically scale resources based on real-time needs. &lt;strong&gt;Auto Scaling&lt;/strong&gt; ensures that your applications remain available and responsive, optimizing both cost and performance by automatically adjusting compute resources to handle varying traffic loads.&lt;/p&gt;

&lt;p&gt;A key feature of AWS’s elasticity is the ability to use &lt;strong&gt;Auto Scaling Groups (ASGs)&lt;/strong&gt; to automatically add or remove compute resources based on demand. This allows your applications to stay highly available even during traffic spikes while also scaling down during periods of low activity to save costs.&lt;/p&gt;

&lt;p&gt;In this tutorial, you'll set up the foundation for a scalable architecture by creating a &lt;strong&gt;Virtual Private Cloud (VPC)&lt;/strong&gt; with three public subnets spread across different availability zones (AZs). This ensures high availability by distributing resources across isolated locations, reducing the risk of downtime due to failures in a single zone. After configuring the VPC, you'll introduce an Auto Scaling Group and an Application Load Balancer (ALB) to distribute traffic across multiple EC2 instances, ensuring that your infrastructure dynamically adapts to changes in traffic demand.&lt;/p&gt;




&lt;h3&gt;
  
  
  By the end of this guide, you will learn how to:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a VPC&lt;/strong&gt; with public subnets in different availability zones for high availability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Launch EC2 instances&lt;/strong&gt; within those subnets running a web application (Apache web server).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set up an Application Load Balancer (ALB)&lt;/strong&gt; to distribute traffic across instances.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configure Auto Scaling Groups (ASG)&lt;/strong&gt; to automatically scale instances based on CPU utilization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test Auto Scaling&lt;/strong&gt; by simulating high traffic to observe how your infrastructure adapts.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Before getting started, ensure that you have the following prerequisites in place to successfully implement Auto Scaling and Load Balancing for your web application. First, you'll need an active AWS account, which you can set up by &lt;a href="https://aws.amazon.com/free/" rel="noopener noreferrer"&gt;creating a free-tier AWS account&lt;/a&gt;. The free-tier provides limited, cost-free access to various AWS services that will be used in this guide. Additionally, it's helpful to have a basic understanding of AWS console to follow along with the configurations more effectively. Finally, for visualizing your infrastructure setup, you can use &lt;a href="https://app.diagrams.net/" rel="noopener noreferrer"&gt;draw.io&lt;/a&gt;, an easy-to-use online tool for creating architecture diagrams that can help you map out your environment.&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture Overview
&lt;/h2&gt;

&lt;p&gt;Before diving into the setup, here’s a high-level diagram of the architecture you’ll be building:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn912nz4t92rhxdaiof8b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn912nz4t92rhxdaiof8b.png" alt="Architecture Diagram of the Scalable Webapp" width="800" height="631"&gt;&lt;/a&gt;&lt;br&gt;Fig: Architecture Diagram of the Scalable Web Application
  &lt;/p&gt;

&lt;p&gt;The components of the architecture include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A VPC with a CIDR block of &lt;code&gt;10.0.0.0/16&lt;/code&gt;&lt;/strong&gt;: This provides an isolated network environment for your resources in AWS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Three Public Subnets&lt;/strong&gt;: Each subnet resides in a different availability zone (AZ) to ensure high availability and fault tolerance.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public Subnet 1&lt;/strong&gt;: &lt;code&gt;10.0.10.0/24&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public Subnet 2&lt;/strong&gt;: &lt;code&gt;10.0.20.0/24&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public Subnet 3&lt;/strong&gt;: &lt;code&gt;10.0.30.0/24&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;An Internet Gateway (IGW)&lt;/strong&gt;: Allows instances within the public subnets to access the internet.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;A Route Table&lt;/strong&gt;: Configures routing for internet-bound traffic from the subnets to the Internet Gateway.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;EC2 Instances&lt;/strong&gt;: These instances will run an Apache web server, deployed across the public subnets to handle web traffic.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;An Auto Scaling Group (ASG)&lt;/strong&gt;: Automatically adjusts the number of EC2 instances based on traffic demand, using CPU utilization as a scaling metric.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;An Application Load Balancer (ALB)&lt;/strong&gt;: Distributes incoming traffic across the EC2 instances to ensure load balancing and even request distribution.&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;A Target Group&lt;/strong&gt;: Registers the EC2 instances behind the ALB and defines health check parameters, ensuring that only healthy instances receive traffic.&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1: Creating the VPC
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Accessing the VPC Dashboard
&lt;/h3&gt;

&lt;p&gt;To begin, you’ll create a VPC based on the architecture diagram above.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Log into AWS&lt;/strong&gt; and navigate to the &lt;strong&gt;VPC Dashboard&lt;/strong&gt; by selecting &lt;strong&gt;Services&lt;/strong&gt; &amp;gt; &lt;strong&gt;VPC&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;On the left-hand menu, click &lt;strong&gt;Create VPC&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqe1b3s1vwggniejw6hg6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqe1b3s1vwggniejw6hg6.png" alt="VPC Dashboard" width="800" height="449"&gt;&lt;/a&gt;&lt;br&gt;Fig: VPC Dashboard
  &lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Configure the VPC
&lt;/h3&gt;

&lt;p&gt;You’ll now configure the VPC to form the core network environment for your resources.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On the &lt;strong&gt;Create VPC&lt;/strong&gt; page, select the &lt;strong&gt;VPC and more&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;VPC settings&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name Tag&lt;/strong&gt;: Enter a name for your VPC (e.g., &lt;code&gt;WebappVPC&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IPv4 CIDR Block&lt;/strong&gt;: Enter &lt;code&gt;10.0.0.0/16&lt;/code&gt; to give the VPC 65,536 IP addresses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IPv6 CIDR Block&lt;/strong&gt;: Leave this option disabled unless IPv6 is required.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tenancy&lt;/strong&gt;: Select &lt;code&gt;Default&lt;/code&gt; unless dedicated hardware is needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhuq6g84zhmkb0jcntbr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhuq6g84zhmkb0jcntbr.png" alt="VPC Configuration" width="640" height="810"&gt;&lt;/a&gt;&lt;br&gt;Fig: VPC Configuration
  &lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3: Configure Subnets
&lt;/h3&gt;

&lt;p&gt;Next, you will configure three public subnets, each in a different availability zone for high availability.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Number of Availability Zones (AZs)&lt;/strong&gt;: Choose &lt;code&gt;3&lt;/code&gt; to ensure high availability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Number of Public Subnets&lt;/strong&gt;: Enter &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customize Subnet CIDR Blocks&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public Subnet 1&lt;/strong&gt;: &lt;code&gt;10.0.10.0/24&lt;/code&gt; in &lt;code&gt;us-east-1a&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public Subnet 2&lt;/strong&gt;: &lt;code&gt;10.0.20.0/24&lt;/code&gt; in &lt;code&gt;us-east-1b&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public Subnet 3&lt;/strong&gt;: &lt;code&gt;10.0.30.0/24&lt;/code&gt; in &lt;code&gt;us-east-1c&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These subnets will reside in different availability zones to ensure high availability across your infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi123f1tst3vpt8uy3oke.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi123f1tst3vpt8uy3oke.png" alt="Subnet Configuration" width="628" height="604"&gt;&lt;/a&gt;&lt;br&gt;Fig: Subnet Configuration
  &lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4: Configure Additional Resources
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Route Table and Internet Gateway
&lt;/h4&gt;

&lt;p&gt;When using the VPC wizard (the &lt;strong&gt;VPC and More&lt;/strong&gt; option), AWS automatically handles the creation of route tables and an Internet Gateway. The wizard not only generates the required route table and Internet Gateway for your VPC but also sets up the necessary routes for internet-bound traffic. This ensures that instances in the public subnets can communicate with the internet.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5: Review and Launch
&lt;/h3&gt;

&lt;p&gt;After configuring the VPC, subnets, Internet Gateway, and route table, you’re ready to launch the VPC.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Review all the configurations on the &lt;strong&gt;Summary&lt;/strong&gt; page.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create VPC&lt;/strong&gt; to launch the network environment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3eome7i7l3xptdfsx0u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3eome7i7l3xptdfsx0u.png" alt="VPC Creation Workflow and Preview" width="800" height="249"&gt;&lt;/a&gt;&lt;br&gt;Fig: VPC Creation Workflow and Preview
  &lt;/p&gt;

&lt;p&gt;Your VPC is now created and ready for use, laying the foundation for a highly available, scalable web application architecture.&lt;/p&gt;




&lt;h2&gt;
  
  
  Section 2: Deploying an EC2 Instance
&lt;/h2&gt;

&lt;p&gt;With the VPC setup complete, it's time to launch EC2 instances into one of the public subnets. These instances will serve as web servers for hosting your applications, allowing you to test connectivity and functionality within your newly created VPC.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Launch an EC2 Instance
&lt;/h2&gt;

&lt;p&gt;To launch an EC2 instance, follow these steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Navigate to the EC2 Dashboard
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Log into the &lt;strong&gt;AWS Management Console&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;EC2&lt;/strong&gt; from the list of services.&lt;/li&gt;
&lt;li&gt;Click on &lt;strong&gt;Launch Instance&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjixldltgpnfkdv4rkonn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjixldltgpnfkdv4rkonn.png" alt="EC2 Dashboard" width="800" height="387"&gt;&lt;/a&gt;&lt;br&gt;Fig: EC2 Dashboard
  &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Configure the Instance Details
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name and Tags&lt;/strong&gt;: Assign a meaningful name to your instance (e.g., &lt;code&gt;WebServer&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AMI Selection&lt;/strong&gt;: Choose the &lt;strong&gt;Amazon Linux 2023&lt;/strong&gt; AMI. Amazon Linux is free-tier eligible and supports package management through &lt;code&gt;yum&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instance Type&lt;/strong&gt;: Select &lt;strong&gt;t2.micro&lt;/strong&gt;, which is free-tier eligible and suitable for testing and small applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F19bkdewgzy9oziknu4y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F19bkdewgzy9oziknu4y0.png" alt="Instance Type Selection" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;Fig: Instance Type Selection
  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Key Pair Setup
&lt;/h2&gt;

&lt;p&gt;A key pair is required to securely access your instance via SSH. If you don’t have an existing key pair, create a new one:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Key Pair&lt;/strong&gt;: Choose an existing key pair or create a new one.

&lt;ul&gt;
&lt;li&gt;If creating a new key pair:

&lt;ul&gt;
&lt;li&gt;Enter a name for the key pair.&lt;/li&gt;
&lt;li&gt;Download the &lt;code&gt;.pem&lt;/code&gt; file and store it securely. You will need this file to SSH into your EC2 instance later.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs04l0q1z06623vhgpikr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs04l0q1z06623vhgpikr.png" alt="Key Pair Setup" width="800" height="244"&gt;&lt;/a&gt;&lt;br&gt;Fig: Key Pair Setup
  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09i7mwxmd51sgudld38a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09i7mwxmd51sgudld38a.png" alt="Key Pair Setup" width="778" height="850"&gt;&lt;/a&gt;&lt;br&gt;Fig: Key Pair Setup
  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Configure Network Settings
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VPC&lt;/strong&gt;: Select the VPC you created in the previous section (e.g., &lt;code&gt;WebappVPC&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subnet&lt;/strong&gt;: Choose &lt;strong&gt;Public Subnet 1&lt;/strong&gt; (e.g., &lt;code&gt;10.0.10.0/24&lt;/code&gt;). This ensures that your instance has internet access via the Internet Gateway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auto-assign Public IP&lt;/strong&gt;: Ensure that this option is &lt;strong&gt;enabled&lt;/strong&gt;. This automatically assigns a public IP to the instance, which is essential for testing your web server over the internet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscioma6kqlcf60dzbq81.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fscioma6kqlcf60dzbq81.png" alt="Network Settings" width="800" height="599"&gt;&lt;/a&gt;&lt;br&gt;Fig: Network Settings
  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Configure Security Groups
&lt;/h2&gt;

&lt;p&gt;Security groups control inbound and outbound traffic to your instance. Here's how to configure them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create or Choose a Security Group&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Under the &lt;strong&gt;Network Settings&lt;/strong&gt; section, select &lt;strong&gt;Create security group&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Name it &lt;code&gt;webapp-security-group&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inbound Rules&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Allow SSH (Port 22)&lt;/strong&gt;: Enables SSH access to your instance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source&lt;/strong&gt;: For enhanced security, restrict to your IP address. For learning purposes, you can set it to &lt;code&gt;0.0.0.0/0&lt;/code&gt; to allow access from anywhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allow HTTP (Port 80)&lt;/strong&gt;: Permits web traffic to your Apache server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source&lt;/strong&gt;: Set to &lt;code&gt;0.0.0.0/0&lt;/code&gt; to allow access from the internet.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Outbound Rules&lt;/strong&gt;: By default, the security group allows all outbound traffic. No changes are necessary unless specific outbound restrictions are required.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsbtolq3fx1lrggslucwc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsbtolq3fx1lrggslucwc.png" alt="Security Group Setup" width="800" height="525"&gt;&lt;/a&gt;&lt;br&gt;Fig: Security Group Setup
  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: User Data Configuration
&lt;/h2&gt;

&lt;p&gt;Add the following &lt;strong&gt;User Data&lt;/strong&gt; script under &lt;strong&gt;Advanced Details&lt;/strong&gt;. This script will automatically install and start the Apache web server when the instance launches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
yum update &lt;span class="nt"&gt;-y&lt;/span&gt;
yum &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; httpd
systemctl start httpd
systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;httpd
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;h1&amp;gt;Hello world! This is &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/h1&amp;gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /var/www/html/index.html

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Updates the instance's packages.&lt;/li&gt;
&lt;li&gt;Installs the Apache web server (&lt;code&gt;httpd&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Starts the Apache service and enables it to start automatically on boot.&lt;/li&gt;
&lt;li&gt;Creates a simple HTML page that displays the instance's hostname.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjn7gezng4vuoqaetglw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjn7gezng4vuoqaetglw.png" alt="User Data Setup" width="800" height="658"&gt;&lt;/a&gt;&lt;br&gt;Fig: User Data Setup
  &lt;/p&gt;

&lt;h3&gt;
  
  
  7. &lt;strong&gt;Launch the Instance&lt;/strong&gt;: After configuring the above settings, click &lt;strong&gt;Launch Instance&lt;/strong&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fobrk6i45zqdjogg1t3w3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fobrk6i45zqdjogg1t3w3.png" alt="Launching EC2 Instance" width="800" height="465"&gt;&lt;/a&gt;&lt;br&gt;Fig: Launching EC2 Instance
  &lt;/p&gt;

&lt;h3&gt;
  
  
  8. &lt;strong&gt;Testing the EC2 Instance&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once the instance has launched, you can test the setup by selecting the &lt;code&gt;WebServer&lt;/code&gt; instance and copying its public IP address.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Testing the Apache Web Server&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Open a web browser and navigate to the instance's public IP.&lt;/li&gt;
&lt;li&gt;You should see the message: &lt;code&gt;Hello world! This is &amp;lt;hostname&amp;gt;&lt;/code&gt; displayed on the webpage, confirming that Apache is running and serving the HTML file created using the User Data script.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31zvy85462tfgmc8jakl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31zvy85462tfgmc8jakl.png" alt="Testing Apache Web Server" width="800" height="632"&gt;&lt;/a&gt;&lt;br&gt;Fig: Testing Apache Web Server
  &lt;/p&gt;




&lt;h3&gt;
  
  
  Summary of What We've Done So Far
&lt;/h3&gt;

&lt;p&gt;At this stage, we've successfully set up a single EC2 instance running an Apache web server within a public subnet of our VPC. By accessing this instance through its public IP, we confirmed that the web server is running and serving content. However, all incoming traffic currently hits just this one instance, meaning that if demand increases beyond its capacity, performance could degrade, or the server might even become unresponsive.&lt;/p&gt;

&lt;p&gt;To address this, the next step is to set up &lt;strong&gt;Auto Scaling&lt;/strong&gt;. This will allow us to automatically launch new EC2 instances as demand increases and terminate them when traffic reduces, ensuring that our application remains responsive and cost-efficient. We'll also configure an &lt;strong&gt;Application Load Balancer (ALB)&lt;/strong&gt; to distribute traffic across multiple instances, ensuring even distribution and redundancy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Section 3: Setting Up Auto Scaling and Load Balancing
&lt;/h2&gt;

&lt;p&gt;Now that you’ve successfully deployed an EC2 instance, the next step is to implement &lt;strong&gt;Auto Scaling&lt;/strong&gt; and an &lt;strong&gt;Application Load Balancer (ALB)&lt;/strong&gt;. This will ensure that your architecture dynamically scales in response to traffic demands, maintaining optimal performance and fault tolerance.&lt;/p&gt;

&lt;p&gt;We’ll start by creating the Application Load Balancer (ALB), which will distribute incoming traffic across multiple instances. Then, we’ll configure the Auto Scaling Group (ASG) to automatically add or remove instances based on CPU utilization. For this tutorial, we'll use the default region &lt;strong&gt;us-east-1&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting Up Auto Scaling
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Create a New Target Group
&lt;/h3&gt;

&lt;p&gt;The ALB uses a &lt;strong&gt;Target Group&lt;/strong&gt; to route traffic to specific EC2 instances. Let’s set one up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Target Group Name&lt;/strong&gt;: Enter a name for the target group (e.g., &lt;code&gt;WebApp-TG&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target Type&lt;/strong&gt;: Select &lt;code&gt;Instance&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocol&lt;/strong&gt;: Choose &lt;code&gt;HTTP&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port&lt;/strong&gt;: Enter &lt;code&gt;80&lt;/code&gt; (for HTTP traffic).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC&lt;/strong&gt;: Choose the same VPC (&lt;code&gt;WebAppVPC&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Health Checks&lt;/strong&gt;: Leave the default settings. The ALB will regularly check the health of your instances to ensure that only healthy instances receive traffic. Click &lt;strong&gt;Next&lt;/strong&gt; and proceed to add targets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F803nl4ibmkm8yivkk446.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F803nl4ibmkm8yivkk446.png" alt="Configure Target Group" width="800" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujlatyowimoxn0ce25qw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujlatyowimoxn0ce25qw.png" alt="Configure Target Group" width="800" height="525"&gt;&lt;/a&gt;&lt;br&gt;Fig: Configuring Target Group
  &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Register Targets
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Register Existing Instances&lt;/strong&gt;: Manually register your existing &lt;code&gt;webapp-server&lt;/code&gt; EC2 instance. The Auto Scaling Group (ASG) will handle this automatically in the future. Click &lt;strong&gt;Next&lt;/strong&gt; to proceed to registering targets and creating the Target Group.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6v5g4sclqrl9sgbrfdym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6v5g4sclqrl9sgbrfdym.png" alt="Registering Existing Instance to Target Group" width="800" height="378"&gt;&lt;/a&gt;&lt;br&gt;Fig: Registering Existing Instance to Target Group
  &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Review and Create
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Review your Target Group configuration.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create Target Group&lt;/strong&gt; to finalize the setup.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fae94ju413s9w3l5az0mr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fae94ju413s9w3l5az0mr.png" alt="Target Group Dashboard" width="800" height="383"&gt;&lt;/a&gt;&lt;br&gt;Fig: Target Group Dashboard
  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now that your Target Group is created, you can proceed to create your load balancer, which will route traffic to the instances in your Target Group.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Setting Up an Application Load Balancer (ALB)
&lt;/h2&gt;

&lt;p&gt;An ALB is essential for distributing traffic across multiple instances, ensuring that no single instance becomes overwhelmed. Here’s how to set it up:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Access the EC2 Dashboard
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;AWS Management Console&lt;/strong&gt;, go to the &lt;strong&gt;EC2 Dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;On the left-hand side, under &lt;strong&gt;Load Balancing&lt;/strong&gt;, select &lt;strong&gt;Load Balancers&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Create a New Load Balancer
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Click on &lt;strong&gt;Create Load Balancer&lt;/strong&gt; and select &lt;strong&gt;Application Load Balancer&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyo0ii229tsc5lj3nvwbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyo0ii229tsc5lj3nvwbg.png" alt="Create Application Load Balancer" width="800" height="662"&gt;&lt;/a&gt;&lt;br&gt;Fig: Creating an Application Load Balancer
  &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Configure Load Balancer Settings
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name&lt;/strong&gt;: Enter a name for your load balancer (e.g., &lt;code&gt;WebApp-ALB&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheme&lt;/strong&gt;: Choose &lt;code&gt;Internet-facing&lt;/code&gt; to make the ALB accessible over the internet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IP Address Type&lt;/strong&gt;: Select &lt;code&gt;IPv4&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC&lt;/strong&gt;: Choose the VPC you created earlier (e.g., &lt;code&gt;WebAppVPC&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Availability Zones&lt;/strong&gt;: Select the availability zones and subnets where your EC2 instances are deployed (in this case, the three public subnets you created: &lt;code&gt;10.0.10.0/24&lt;/code&gt;, &lt;code&gt;10.0.20.0/24&lt;/code&gt;, and &lt;code&gt;10.0.30.0/24&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2e0nfj40es5rte3hruc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2e0nfj40es5rte3hruc1.png" alt="Configure Load Balancer Settings" width="800" height="459"&gt;&lt;/a&gt;&lt;br&gt;Fig: Configuring Load Balancer Settings
  &lt;/p&gt;

&lt;h3&gt;
  
  
  4. Configure Security Settings
&lt;/h3&gt;

&lt;p&gt;Since you’re working with HTTP (port 80), there’s no need to configure an SSL certificate. You can skip this section for now. However, in production environments, you should consider enabling SSL for secure connections (HTTPS).&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Configure Security Groups
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Select or create a security group for your ALB. Ensure that it allows &lt;strong&gt;inbound HTTP (port 80)&lt;/strong&gt; traffic from anywhere (&lt;code&gt;0.0.0.0/0&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once your ALB is created, it will start listening for HTTP requests and distributing them across instances via the Auto Scaling Group. However, before that, you need to create an AMI for your launch template that you will use in setting up your Auto Scaling Group.&lt;/p&gt;




&lt;h2&gt;
  
  
  Creating an AMI from Your Running EC2 Instance
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Go to EC2 Dashboard&lt;/strong&gt;: Navigate to &lt;strong&gt;Instances&lt;/strong&gt; and select your running instance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.1. &lt;strong&gt;Actions&lt;/strong&gt;: Click on &lt;strong&gt;Actions&lt;/strong&gt; &amp;gt; &lt;strong&gt;Image and templates&lt;/strong&gt; &amp;gt; &lt;strong&gt;Create Image&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokuv5g5900z8j2uiy9li.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokuv5g5900z8j2uiy9li.png" alt="Creating an AMI" width="800" height="311"&gt;&lt;/a&gt;&lt;br&gt;Fig: Creating an AMI
  &lt;/p&gt;

&lt;p&gt;2.2. &lt;strong&gt;Image Name&lt;/strong&gt;: Provide a name for your AMI (e.g., &lt;code&gt;webapp-server-image&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;2.3. &lt;strong&gt;Instance Volumes&lt;/strong&gt;: Review the instance storage configuration.&lt;/p&gt;

&lt;p&gt;2.4. &lt;strong&gt;Create Image&lt;/strong&gt;: Click &lt;strong&gt;Create Image&lt;/strong&gt; to start the process.&lt;/p&gt;

&lt;p&gt;2.5. &lt;strong&gt;Find AMI ID&lt;/strong&gt;: Once the image is created, go to &lt;strong&gt;AMIs&lt;/strong&gt; in the EC2 Dashboard to find your new AMI ID. You'll use this ID when configuring your launch template.&lt;/p&gt;

&lt;p&gt;This AMI will be the base image for your Auto Scaling instances. Now that you have the AMI, you can continue to create the Launch Template for your Auto Scaling Group.&lt;/p&gt;




&lt;h2&gt;
  
  
  Creating a Launch Template for Auto Scaling
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Go to EC2 Dashboard&lt;/strong&gt;: Navigate to &lt;strong&gt;Launch Templates&lt;/strong&gt; and click &lt;strong&gt;Create Launch Template&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.1 &lt;strong&gt;Launch Template Name&lt;/strong&gt;: Enter a name (e.g., &lt;code&gt;WebApp-LT&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1yjr85mgydg1gbgz360p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1yjr85mgydg1gbgz360p.png" alt="Launch Template Creation" width="800" height="664"&gt;&lt;/a&gt;&lt;br&gt;Fig: Launch Template Creation
  &lt;/p&gt;

&lt;p&gt;2.2 &lt;strong&gt;AMI ID&lt;/strong&gt;: Go to &lt;strong&gt;My AMIs&lt;/strong&gt; and enter the AMI ID you created earlier (&lt;code&gt;WebApp-webserver-image&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbakuj112sbfsct8t8y3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbakuj112sbfsct8t8y3o.png" alt="AMI ID Selection" width="800" height="672"&gt;&lt;/a&gt;&lt;br&gt;Fig: AMI ID Selection
  &lt;/p&gt;

&lt;p&gt;2.3 &lt;strong&gt;Instance Type&lt;/strong&gt;: Select an instance type (e.g., &lt;code&gt;t2.micro&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;2.4 &lt;strong&gt;Key Pair&lt;/strong&gt;: Choose your existing key pair for SSH access (&lt;code&gt;webapp-key-pair&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2spovkkmch1hcemjrfed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2spovkkmch1hcemjrfed.png" alt="Key Pair Selection" width="800" height="613"&gt;&lt;/a&gt;&lt;br&gt;Fig: Key Pair Selection
  &lt;/p&gt;

&lt;p&gt;2.5 &lt;strong&gt;Security Groups&lt;/strong&gt;: Attach the security group created earlier for your EC2 instances (&lt;code&gt;WebApp-Security-Group&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3494ctmghqrdq6eblpm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3494ctmghqrdq6eblpm7.png" alt="Security Group Attachment" width="800" height="571"&gt;&lt;/a&gt;&lt;br&gt;Fig: Security Group Attachment
  &lt;/p&gt;

&lt;p&gt;2.6 &lt;strong&gt;Auto-assign Public IP&lt;/strong&gt;: Under &lt;code&gt;Advanced Network Configurations&lt;/code&gt;, enable public IP assignment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8awory0x5efukbydjmcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8awory0x5efukbydjmcg.png" alt="Auto-assign Public IP" width="800" height="667"&gt;&lt;/a&gt;&lt;br&gt;Fig: Auto-assign Public IP
  &lt;/p&gt;

&lt;p&gt;2.7 &lt;strong&gt;User Data&lt;/strong&gt;: Add the user data for the instances that will be created by the auto scaling group. In this demo we are adding the same user data as our existing webserver.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv1jluyt8ejbxv2cob4h2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv1jluyt8ejbxv2cob4h2.png" alt="Launch Template User data" width="800" height="383"&gt;&lt;/a&gt;&lt;br&gt;Fig: Launch Template User data
  &lt;/p&gt;

&lt;p&gt;2.8 &lt;strong&gt;Create Template&lt;/strong&gt;: Click &lt;strong&gt;Create Launch Template&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  This template will serve as the blueprint for launching instances in your Auto Scaling Group.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 2: Configuring Auto Scaling Groups (ASG)
&lt;/h3&gt;

&lt;p&gt;Next, we’ll set up the Auto Scaling Group using our launch template to automatically adjust the number of EC2 instances based on CPU utilization, ensuring the application can handle traffic surges. &lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Navigate to Auto Scaling&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In the AWS Management Console, go to &lt;strong&gt;EC2 Dashboard&lt;/strong&gt;, and on the left-hand menu, under &lt;strong&gt;Auto Scaling&lt;/strong&gt;, click on &lt;strong&gt;Auto Scaling Groups&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Create Auto Scaling Group&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Click on &lt;strong&gt;Create Auto Scaling Group&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Configure Auto Scaling Group Settings&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Auto Scaling Group Name&lt;/strong&gt;: Enter a name for the group (e.g., &lt;code&gt;WebApp-ASG&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffo96gdyfirzz6jaabqqe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffo96gdyfirzz6jaabqqe.png" alt="Auto Scaling Group Settings" width="800" height="457"&gt;&lt;/a&gt;&lt;br&gt;Fig: Auto Scaling Group Settings
  &lt;/p&gt;

&lt;h4&gt;
  
  
  4. &lt;strong&gt;Configure Network Settings&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VPC&lt;/strong&gt;: Select your VPC (&lt;code&gt;WebAppVPC&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subnets&lt;/strong&gt;: Choose the three public subnets you created (&lt;code&gt;10.0.10.0/24&lt;/code&gt;, &lt;code&gt;10.0.20.0/24&lt;/code&gt;, and &lt;code&gt;10.0.30.0/24&lt;/code&gt;).

&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe3dn8m3rvct1ntxmrdvx.png" alt="Auto Scaling Group Network Settings" width="800" height="492"&gt;Fig: Auto Scaling Group Network Settings

&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5. &lt;strong&gt;Attach the Load Balancer&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;strong&gt;Attach to an existing load balancer&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Choose the &lt;strong&gt;Application Load Balancer&lt;/strong&gt; created earlier (&lt;code&gt;WebApp-ALB&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;Target Group&lt;/strong&gt; (&lt;code&gt;WebApp-TG&lt;/code&gt;) created for the ALB.&lt;/li&gt;
&lt;li&gt;Turn on Elastic Load Balancing health checks.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Additional settings&lt;/strong&gt; Enable default instance warmup of &lt;code&gt;60s&lt;/code&gt;click &lt;code&gt;Next&lt;/code&gt; to continue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwyxsifvevpu7561kyxa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwyxsifvevpu7561kyxa.png" alt="Attach Load Balancer to Auto Scaling Group" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft54im0dr11317ae9j460.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft54im0dr11317ae9j460.png" alt="Attach Load Balancer to Auto Scaling Group" width="800" height="426"&gt;&lt;/a&gt;&lt;br&gt;Fig: Attach Load Balancer to Auto Scaling Group
  &lt;/p&gt;

&lt;h4&gt;
  
  
  6. &lt;strong&gt;Configure Instance Numbers&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Desired Capacity&lt;/strong&gt;: Set to &lt;code&gt;1&lt;/code&gt; (this means there will always be at least 1 instances running).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimum Capacity&lt;/strong&gt;: Set to &lt;code&gt;1&lt;/code&gt; (this means the ASG will never terminate the last running instance).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maximum Capacity&lt;/strong&gt;: Set to &lt;code&gt;4&lt;/code&gt; (this allows Auto Scaling to scale up to 4 instances if needed).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc9iuuscieafwd4hv87z4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc9iuuscieafwd4hv87z4.png" alt="Configure Instance Numbers" width="800" height="478"&gt;&lt;/a&gt;&lt;br&gt;Fig: Configuring Instance Numbers
  &lt;/p&gt;

&lt;h4&gt;
  
  
  7. &lt;strong&gt;Configure Scaling Policies&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Now we’ll configure the scaling policies that will trigger instance creation or termination based on CPU utilization.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;strong&gt;Target Tracking Scaling Policy&lt;/strong&gt;.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Policy Type&lt;/strong&gt;: Choose &lt;code&gt;Target tracking scaling policy&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metric type&lt;/strong&gt;: Average CPU utilization&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Target Value&lt;/strong&gt;: Enter &lt;code&gt;25%&lt;/code&gt; (this means new instances will be launched when average CPU utilization exceeds 25%, and instances will be terminated when it's below 25%).
Leave any other setting at default and continue.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd38ccj1hmjqucgeeml9u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd38ccj1hmjqucgeeml9u.png" alt="Auto Scaling Policies" width="800" height="541"&gt;&lt;/a&gt;&lt;br&gt;Fig: Configuring Auto Scaling Policies
  &lt;/p&gt;

&lt;h4&gt;
  
  
  8. &lt;strong&gt;Review and Create&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Review the configuration, then click &lt;strong&gt;Create Auto Scaling Group&lt;/strong&gt;.

&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0rtgpfcz5qw7t0m3ausu.png" alt="Auto Scaling Policies" width="800" height="156"&gt;Fig: Auto scaling group dashboard

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The ASG will now automatically adjust the number of instances based on CPU utilization and distribute traffic across them using the ALB. We can evaluate this by testing the auto scaling using CPU stress.&lt;/p&gt;




&lt;h2&gt;
  
  
  Section 4: Testing Auto Scaling
&lt;/h2&gt;

&lt;p&gt;To verify that your Auto Scaling setup is functioning correctly, you can simulate high traffic or load on the instances to trigger the creation of new instances.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Connect to an EC2 Instance
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;SSH into Your EC2 Instance&lt;/strong&gt; using EC2 Connect or the AWS CLI with the following command:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; /path/to/your-key.pem ec2-user@&amp;lt;Public-IP-of-EC2-Instance&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Install the Stress Tool
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Once connected, install the &lt;code&gt;stress&lt;/code&gt; tool to simulate high CPU load:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;yum &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; stress
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuu8uxr9qwjyepdgz6rf4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuu8uxr9qwjyepdgz6rf4.png" alt="Installing the Stress Tool" width="800" height="376"&gt;&lt;/a&gt;&lt;br&gt;Fig: Installing the Stress Tool
  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Simulate High CPU Load
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Run the &lt;code&gt;stress&lt;/code&gt; command to simulate high CPU load for a set period (e.g., 100 seconds):&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;stress &lt;span class="nt"&gt;-c&lt;/span&gt; 1 &lt;span class="nt"&gt;-i&lt;/span&gt; 1 &lt;span class="nt"&gt;-m&lt;/span&gt; 1 &lt;span class="nt"&gt;--vm-bytes&lt;/span&gt; 128M &lt;span class="nt"&gt;-t&lt;/span&gt; 100s
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftpps33ejff7pjwqttxr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftpps33ejff7pjwqttxr.png" alt="Simulating CPU Load" width="800" height="221"&gt;&lt;/a&gt;&lt;br&gt;Fig: Simulating High CPU Load
  &lt;/p&gt;

&lt;p&gt;This command generates CPU load on one core (since &lt;code&gt;t2.micro&lt;/code&gt; has just 1 vCPU) for 100 seconds. As a result, the CPU utilization should exceed the 25% threshold set in the Auto Scaling Group (ASG), triggering the ASG to launch new instances to handle the increased load.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqh2cqq7axb4fo71km4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqh2cqq7axb4fo71km4e.png" alt="Auto Scaling in Action" width="800" height="387"&gt;&lt;/a&gt;&lt;br&gt;Fig: Auto Scaling Group Scaling Activity
  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Verify Auto Scaling
&lt;/h2&gt;

&lt;p&gt;In this section, we will verify that Auto Scaling is functioning as expected by simulating a CPU load, monitoring the Auto Scaling Group (ASG) activity, and checking the Load Balancer's traffic distribution across instances.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Monitor Auto Scaling Group Activity
&lt;/h3&gt;

&lt;p&gt;Once you've triggered a high CPU load using the &lt;code&gt;stress&lt;/code&gt; tool, Auto Scaling should kick in when the CPU utilization exceeds the threshold of 25%. You can monitor the ASG activity to confirm that new instances are being launched.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Navigate to Auto Scaling Groups&lt;/strong&gt; in the AWS Management Console.&lt;/li&gt;
&lt;li&gt;Select your Auto Scaling Group (&lt;code&gt;WebApp-ASG&lt;/code&gt;) and go to the &lt;strong&gt;Activity&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;You should observe scaling activities showing that new instances are being created because the CPU utilization exceeded the threshold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjyoov0d5oyvocjqhy2qz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjyoov0d5oyvocjqhy2qz.png" alt="Auto Scaling Group Activity" width="800" height="90"&gt;&lt;/a&gt;&lt;br&gt;Fig: Auto Scaling Group Activity Triggered by High CPU Usage
  &lt;/p&gt;

&lt;p&gt;This activity confirms that Auto Scaling is working as intended, scaling the number of instances up in response to increased CPU usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Monitor Instance CPU Usage
&lt;/h3&gt;

&lt;p&gt;Next, we can validate the specific CPU spike caused by the &lt;code&gt;stress&lt;/code&gt; tool. The CPU usage of the instance will show a spike above 25%, which is what triggered the Auto Scaling.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Navigate to the EC2 Dashboard&lt;/strong&gt; and select the instance running the stress test.&lt;/li&gt;
&lt;li&gt;Go to the &lt;strong&gt;Monitoring&lt;/strong&gt; tab and view the CPU utilization metrics.&lt;/li&gt;
&lt;li&gt;You should observe a CPU spike to 40.9% during the stress test, which caused Auto Scaling to add additional instances.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg359axxk4kasbk22i3t8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg359axxk4kasbk22i3t8.png" alt="EC2 Instance CPU Monitoring" width="800" height="388"&gt;&lt;/a&gt;&lt;br&gt;Fig: CPU Usage Spike to 40.9% Due to the Stress Test
  &lt;/p&gt;

&lt;p&gt;This shows that the instance was overloaded, which triggered the ASG to create additional instances.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Verify Load Balancer Traffic Distribution
&lt;/h3&gt;

&lt;p&gt;Once multiple instances are running in the ASG, the Load Balancer should evenly distribute traffic across them. You can confirm this by checking the IP addresses the Load Balancer directs traffic to.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Open a Web Browser&lt;/strong&gt; and navigate to the DNS name of your Application Load Balancer (ALB).&lt;/li&gt;
&lt;li&gt;Refresh the page multiple times and observe the IP addresses assigned to the different EC2 instances.&lt;/li&gt;
&lt;li&gt;You should see the IP address change between two or more instances, confirming that the Load Balancer is properly distributing traffic across multiple servers in the target group.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypungx943ch7wbnxnja4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypungx943ch7wbnxnja4.png" alt="Load Balancer Distributing Traffic" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgx2kt1n3l61r7x5qrj9n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgx2kt1n3l61r7x5qrj9n.png" alt="Load Balancer Distributing Traffic" width="800" height="232"&gt;&lt;/a&gt;&lt;br&gt;Fig: Load Balancer Distributing Traffic Across different Instances running the WebApp
  &lt;/p&gt;

&lt;p&gt;This demonstrates that the Load Balancer is effectively balancing incoming requests across the instances, ensuring high availability.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Terminate Instances and Verify Auto Scaling
&lt;/h3&gt;

&lt;p&gt;To further test the ASG's functionality, you can terminate or stop all running instances and observe how the ASG automatically replaces them to maintain the desired number of instances.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Navigate to the EC2 Dashboard&lt;/strong&gt; and select all instances.&lt;/li&gt;
&lt;li&gt;Terminate or stop all the instances.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once terminated, the Auto Scaling Group will detect that no instances are running and automatically launch a new one to maintain the minimum instance count.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Go back to the Auto Scaling Group Activity&lt;/strong&gt; in the EC2 dashboard to confirm that the ASG is performing checks and launching new instances.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzkuuns4bxd1aqm7nqu3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzkuuns4bxd1aqm7nqu3.png" alt="New Instance Created by ASG After Termination" width="800" height="182"&gt;&lt;/a&gt;&lt;br&gt;Fig: All running Instances manually stopped or Terminated
  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fglh3zwd5wkleotxwzgks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fglh3zwd5wkleotxwzgks.png" alt="New Instance Created by ASG After Termination" width="800" height="135"&gt;&lt;/a&gt;&lt;br&gt;Fig: New Instance Created by ASG After Termination
  &lt;/p&gt;

&lt;p&gt;This confirms that the ASG is functioning correctly by ensuring that there is always at least one instance running, even if instances are terminated or fail.&lt;/p&gt;




&lt;p&gt;This concludes the verification of your Auto Scaling Group, Load Balancer, and EC2 instances. You've successfully demonstrated the dynamic scaling of instances based on CPU usage, proper traffic distribution across multiple instances, and the resilience of your setup in automatically recovering from instance terminations.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, you've successfully set up a highly available and scalable web application architecture on AWS. By creating a &lt;strong&gt;Virtual Private Cloud (VPC)&lt;/strong&gt; with three public subnets across different availability zones, deploying &lt;strong&gt;EC2 instances&lt;/strong&gt; running an Apache web server, and configuring an &lt;strong&gt;Application Load Balancer (ALB)&lt;/strong&gt; and &lt;strong&gt;Auto Scaling Group (ASG)&lt;/strong&gt;, you've ensured that your application can dynamically scale to handle varying traffic loads while optimizing costs and maintaining performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;High Availability&lt;/strong&gt;: Distributing resources across multiple availability zones ensures that your application remains available even if one zone experiences failures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: &lt;strong&gt;Auto Scaling&lt;/strong&gt; automatically adjusts the number of EC2 instances based on demand, ensuring your application can handle traffic spikes and scale down during low usage periods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancing&lt;/strong&gt;: The &lt;strong&gt;ALB&lt;/strong&gt; efficiently distributes incoming traffic across multiple instances, preventing any single instance from becoming a bottleneck.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost Optimization&lt;/strong&gt;: By only using the necessary resources, you optimize costs while maintaining performance and availability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Important: Clean Up Your Environment
&lt;/h3&gt;

&lt;p&gt;To avoid incurring unnecessary charges, it's essential to clean up the resources you created for this tutorial once you've completed the setup and testing. Follow these steps to terminate resources:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Terminate EC2 Instances&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the &lt;strong&gt;EC2 Dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select all instances created for this tutorial.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Actions&lt;/strong&gt; &amp;gt; &lt;strong&gt;Instance State&lt;/strong&gt; &amp;gt; &lt;strong&gt;Terminate&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Delete Auto Scaling Group&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Auto Scaling Groups&lt;/strong&gt; in the EC2 Dashboard.&lt;/li&gt;
&lt;li&gt;Select the ASG (&lt;code&gt;WebApp-ASG&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Delete&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Delete Load Balancer and Target Group&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Load Balancers&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select the ALB (&lt;code&gt;WebApp-ALB&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Actions&lt;/strong&gt; &amp;gt; &lt;strong&gt;Delete&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Target Groups&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select the Target Group (&lt;code&gt;WebApp-TG&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Actions&lt;/strong&gt; &amp;gt; &lt;strong&gt;Delete&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Delete VPC&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the &lt;strong&gt;VPC Dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select the VPC (&lt;code&gt;WebAppVPC&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Ensure all associated resources (subnets, gateways, route tables) are deleted.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Actions&lt;/strong&gt; &amp;gt; &lt;strong&gt;Delete VPC&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By cleaning up your environment, you ensure that you won't be billed for resources you no longer need, making your learning experience both effective and cost-efficient.&lt;/p&gt;




&lt;p&gt;This completes the setup of an Auto Scaling Group with an Application Load Balancer to dynamically handle traffic spikes for a web application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;Here are some helpful resources for further reading on the topics covered in this post:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html" rel="noopener noreferrer"&gt;AWS Auto Scaling Documentation&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/how-elastic-load-balancing-works.html" rel="noopener noreferrer"&gt;AWS Elastic Load Balancing Documentation&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html" rel="noopener noreferrer"&gt;Amazon EC2 User Guide&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html" rel="noopener noreferrer"&gt;AWS CLI Documentation&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>aws</category>
      <category>devops</category>
      <category>cloudcomputing</category>
    </item>
    <item>
      <title>Deploying Basic Infrastructure on AWS with Terraform</title>
      <dc:creator>benny fmo</dc:creator>
      <pubDate>Tue, 20 Aug 2024 11:59:29 +0000</pubDate>
      <link>https://dev.to/bennyfmo_237/deploying-basic-infrastructure-on-aws-with-terraform-1k68</link>
      <guid>https://dev.to/bennyfmo_237/deploying-basic-infrastructure-on-aws-with-terraform-1k68</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In today’s cloud-driven world, managing infrastructure efficiently and consistently is crucial for developers and IT professionals alike. Traditionally, setting up infrastructure involved navigating cloud consoles, configuring networks, launching instances, and ensuring everything was correctly connected—a manual process that was both time-consuming and prone to errors, especially when scaling.&lt;/p&gt;

&lt;p&gt;Enter Terraform, an open-source Infrastructure as Code (IaC) tool that revolutionizes how we build, change, and version our infrastructure. Instead of manually configuring resources, Terraform is a cloud agnostic IaC tool that allows you to define your infrastructure using a simple, human-readable configuration language called HCL (HashiCorp Configuration Language). This approach not only automates deployments but also ensures consistency across environments and makes tracking changes effortless.&lt;/p&gt;

&lt;p&gt;In this blog post, I’ll guide you step by step through deploying a basic infrastructure setup on AWS using Terraform. Whether you're a beginner or just brushing up on your skills, this tutorial will help you get hands-on experience with Terraform and HCL. We’ll cover everything from configuring your environment and writing Terraform code to deploying your first EC2 instance and setting up a simple web server. By the end, you’ll have the foundational knowledge to confidently use Terraform to manage your infrastructure in the cloud.&lt;/p&gt;

&lt;p&gt;So, grab a cup of coffee, fire up your terminal, and let’s dive into the world of Terraform and HCL!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1. What You’ll Need&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before we start, ensure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;AWS Account:&lt;/strong&gt; You'll need an AWS account to provision. You can see how to create an AWS free tier account &lt;a href="https://www.youtube.com/watch?v=3sqAzIb3rRw" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terraform Installed:&lt;/strong&gt; Install Terraform by following the instructions on &lt;a href="https://learn.hashicorp.com/tutorials/terraform/install-cli" rel="noopener noreferrer"&gt;Terraform's official website&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS CLI Installed:&lt;/strong&gt; Install the AWS Command Line Interface (CLI) to configure your credentials. Follow the instructions &lt;a href="https://aws.amazon.com/cli/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VSCode Setup for Terraform:&lt;/strong&gt; Install Visual Studio Code and the &lt;a href="https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform" rel="noopener noreferrer"&gt;HashiCorp Terraform extension&lt;/a&gt; for syntax highlighting, code completion, and linting. This will make writing and managing Terraform configurations easier.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;2. Configuring AWS Authentication&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  a. &lt;strong&gt;Setting Up AWS Credentials&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To allow Terraform to authenticate and interact with AWS, you need to configure your AWS credentials. You can do this using the AWS CLI by running the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll be prompted to enter your AWS Access Key ID, Secret Access Key, default region, and default output format. If you don’t have access keys yet, you can create them in the AWS Management Console under IAM &amp;gt; Users &amp;gt; Security Credentials.&lt;/p&gt;

&lt;h3&gt;
  
  
  b. &lt;strong&gt;Setting Environment Variables (Alternative Method)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Alternatively, you can export your credentials as environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your_access_key
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your_secret_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method is useful if you don’t want to store credentials in a file and it is also a good way to keep your access key confidential.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;3. Writing the Terraform Configuration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this section, we’ll walk through the Terraform code to deploy an EC2 instance on AWS. This EC2 instance will host a simple web server. Before that, let’s take a look at the architecture diagram of the webserver we are creating.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9kbtd8ruynukovltn62p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9kbtd8ruynukovltn62p.jpg" alt="architecture diagram of our webserver" width="800" height="513"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Setting Up VSCode for Terraform&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To write and manage Terraform code effectively, we’ll use Visual Studio Code (VSCode). Follow these steps to set up your development environment:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install VSCode&lt;/strong&gt;: Download and install VSCode from &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Install the Terraform Extension&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;Open VSCode and go to the Extensions Marketplace (&lt;code&gt;Ctrl+Shift+X&lt;/code&gt; or &lt;code&gt;Cmd+Shift+X&lt;/code&gt; on macOS).&lt;/li&gt;
&lt;li&gt;Search for &lt;code&gt;HashiCorp Terraform&lt;/code&gt; and click &lt;strong&gt;Install&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configure Your Workspace&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Create a new folder for your Terraform project (e.g., &lt;code&gt;terraform-webserver&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Open this folder in VSCode by selecting &lt;code&gt;File &amp;gt; Open Folder&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Initialize a New File&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;In the Explorer panel, right-click your project folder and choose &lt;code&gt;New File&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Name the file &lt;code&gt;main.tf&lt;/code&gt;. This is where your Terraform configuration will reside.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  a. &lt;strong&gt;Provider Configuration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once your &lt;code&gt;main.tf&lt;/code&gt; file is created, start by specifying the AWS provider and region:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"aws"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-east-1"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Does:&lt;/strong&gt; This block tells Terraform to use AWS as the provider and to deploy resources in the &lt;code&gt;us-east-1&lt;/code&gt; region.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  b. &lt;strong&gt;Defining the EC2 Instance&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, define the EC2 instance that will run your web server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_instance"&lt;/span&gt; &lt;span class="s2"&gt;"web_server"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ami-04a81a99f5ec58529"&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
  &lt;span class="nx"&gt;vpc_security_group_ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;aws_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;user_data&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;-&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
  #!/bin/bash
  echo "Hello, World" &amp;gt; index.html
  nohup busybox httpd -f -p 8080 &amp;amp;
&lt;/span&gt;&lt;span class="no"&gt;  EOF

&lt;/span&gt;  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"web-server"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AMI:&lt;/strong&gt; The Amazon Machine Image (AMI) ID defines the operating system and applications running on the instance. Here, we're using an Ubuntu AMI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instance Type:&lt;/strong&gt; &lt;code&gt;t2.micro&lt;/code&gt; is a small, free-tier eligible instance type suitable for this exercise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Data:&lt;/strong&gt; This script runs on instance startup, creating an &lt;code&gt;index.html&lt;/code&gt; file and starting a simple web server on port 8080.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tags:&lt;/strong&gt; Tags make it easier to identify your resources.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  c. &lt;strong&gt;Configuring the Security Group&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We need to define a security group to allow traffic on port 8080, which is where our web server will listen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_security_group"&lt;/span&gt; &lt;span class="s2"&gt;"instance"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"terraform-example-instance"&lt;/span&gt;
  &lt;span class="nx"&gt;ingress&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;from_port&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;
    &lt;span class="nx"&gt;to_port&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tcp"&lt;/span&gt;
    &lt;span class="nx"&gt;cidr_blocks&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"0.0.0.0/0"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security Group Name:&lt;/strong&gt; This is the name of the security group.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ingress Rules:&lt;/strong&gt; Allows inbound traffic on port 8080 from any IP address.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvh77njjh60mmwzxxfso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvh77njjh60mmwzxxfso.png" alt="EC2 code on vscode" width="789" height="398"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;4. Initializing Terraform&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once the configuration files are ready, you need to initialize Terraform. Initialization prepares the working directory and downloads the necessary provider plugins.&lt;/p&gt;

&lt;p&gt;Run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Does:&lt;/strong&gt; Downloads the AWS provider and initializes your Terraform working directory. This step is essential before running any other Terraform commands.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favofogmrvvt01f0z38r2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favofogmrvvt01f0z38r2.png" alt="results view of terraform init command" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;5. Planning the Infrastructure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before applying the configuration, you can preview the changes Terraform will make by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Does:&lt;/strong&gt; The &lt;code&gt;plan&lt;/code&gt; command shows you a preview of the infrastructure Terraform will create, modify, or destroy. It helps catch errors and confirm that the configuration is correct before applying any changes as shown on the screenshot below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qpozte576h55qms81zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qpozte576h55qms81zt.png" alt="terraform plan view" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;6. Applying the Configuration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that you’ve reviewed the plan, it’s time to apply the configuration and create the infrastructure.&lt;/p&gt;

&lt;p&gt;Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Does:&lt;/strong&gt; The &lt;code&gt;apply&lt;/code&gt; command provisions the resources as defined in your configuration. Terraform will prompt for confirmation before proceeding. Once confirmed, it will create the EC2 instance and security group as shown on the screenshot below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fax1sys2i03qkoipvz7pc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fax1sys2i03qkoipvz7pc.png" alt="terraform apply results screenshot view" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;7. Verifying the Infrastructure&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  a. &lt;strong&gt;Retrieving the Public IP&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After Terraform finishes applying the configuration, you’ll want to verify that everything is working correctly. To do this, you’ll need the public IP of your EC2 instance. You can find it in the Terraform output or  on the EC2 dashboard of the AWS Management Console.&lt;/p&gt;

&lt;h3&gt;
  
  
  b. &lt;strong&gt;Testing the Web Server&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;With the public IP in hand, test the web server by running the following &lt;code&gt;curl&lt;/code&gt; command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://&amp;lt;public-ip&amp;gt;:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Does:&lt;/strong&gt; This command sends an HTTP GET request to your EC2 instance's public IP on port 8080. If everything is working correctly, you should see the response "Hello, World" in your terminal, confirming that the web server is running.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xq0mgq3n58r1zkxve9f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xq0mgq3n58r1zkxve9f.png" alt="curling public ip of my instance" width="800" height="299"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;8. Cleaning Up&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When you're done with the infrastructure, it's important to clean up the resources to avoid unnecessary charges. You can do this by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What It Does:&lt;/strong&gt; The &lt;code&gt;destroy&lt;/code&gt; command deletes all the resources that Terraform created. Terraform will prompt for confirmation before proceeding with the deletion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspolep36ph4vhjffw4q8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspolep36ph4vhjffw4q8.png" alt="terraform destroy view" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Congratulations! You’ve just deployed a basic infrastructure setup on AWS using Terraform. We walked through the process of configuring AWS authentication, writing Terraform code, initializing Terraform, deploying and verifying an EC2 instance running a web server, and setting up VSCode for Terraform development. This exercise introduced you to key Terraform commands and provided a hands-on example of using Terraform to manage infrastructure on AWS.&lt;/p&gt;

&lt;p&gt;With Terraform, you can easily scale this setup, automate more complex infrastructure, and maintain consistent environments. Keep experimenting, and you’ll soon be able to manage much larger infrastructure deployments!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Resources&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://youtu.be/jJX6S5JAGpI" rel="noopener noreferrer"&gt;Getting Started with Terraform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://k21academy.com/terraform-iac/install-visual-studio-code-for-terraform/" rel="noopener noreferrer"&gt;VSCode Terraform Setup Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" rel="noopener noreferrer"&gt;AWS CLI Installation Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feel free to drop any questions in the comments, and happy coding!&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>aws</category>
      <category>infrastructureascode</category>
      <category>coding</category>
    </item>
    <item>
      <title>What is Infrastructure as Code (IaC) and Why It's Transforming DevOps?</title>
      <dc:creator>benny fmo</dc:creator>
      <pubDate>Sun, 18 Aug 2024 16:45:42 +0000</pubDate>
      <link>https://dev.to/bennyfmo_237/what-is-infrastructure-as-code-iac-and-why-its-transforming-devops-1l2p</link>
      <guid>https://dev.to/bennyfmo_237/what-is-infrastructure-as-code-iac-and-why-its-transforming-devops-1l2p</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The digital landscape is evolving at a breakneck pace, and so are the tools and methodologies that drive it.&lt;/strong&gt; In this era of continuous integration and continuous deployment (CI/CD), automation is no longer a luxury—it's a necessity. One of the most transformative elements in this automation wave is Infrastructure as Code (IaC). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But what exactly is Infrastructure as Code, and why is it making such a significant impact on DevOps?&lt;/strong&gt; For those new to the concept, IaC might seem like just another buzzword in the ever-expanding tech lexicon. However, it's much more than that. IaC represents a paradigm shift in how infrastructure is managed, provisioned, and maintained, turning manual, error-prone tasks into automated, repeatable processes.&lt;/p&gt;

&lt;p&gt;In this article, we’ll break down the essentials of IaC, exploring what it is, how it works, and why it’s becoming a cornerstone of modern DevOps practices. Whether you're a beginner trying to understand the basics or a seasoned developer looking to refine your knowledge, this guide will offer valuable insights into how IaC is transforming the way we think about and implement infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Role of IaC in DevOps
&lt;/h2&gt;

&lt;p&gt;Infrastructure as Code (IaC) plays a pivotal role in the DevOps ecosystem, acting as a catalyst for automation, collaboration, and scalability. Let's explore how IaC integrates seamlessly into DevOps practices and transforms the way teams develop, deploy, and manage applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Automation and Consistency&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In traditional IT environments, infrastructure setup and configuration often involve manual processes that are prone to human error and inconsistency. With IaC, these tasks are automated through code, ensuring that infrastructure is provisioned the same way every time, across all environments. This level of consistency is crucial in DevOps, where maintaining identical environments for development, testing, and production is essential to avoid the "it works on my machine" problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Collaboration and Speed&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;One of the core principles of DevOps is fostering collaboration between development and operations teams. IaC enables this by treating infrastructure configurations as code, which can be versioned, reviewed, and tested just like application code. Developers and operations teams can work together on infrastructure changes, track them in version control systems like Git, and integrate them into CI/CD pipelines.&lt;/p&gt;

&lt;p&gt;This collaborative approach not only speeds up the deployment process but also reduces the time it takes to resolve issues. When infrastructure is defined as code, teams can quickly identify and fix problems by rolling back to previous versions or applying patches, all within a shared codebase.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Scalability&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As businesses grow and demands fluctuate, the ability to scale infrastructure up or down quickly becomes crucial. IaC shines in this aspect by enabling teams to define infrastructure that can be easily replicated or adjusted to meet changing needs. Whether it’s adding more servers, increasing storage capacity, or deploying to multiple regions, IaC allows for rapid and efficient scaling.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For example, if an application experiences a sudden spike in traffic, IaC can automate the process of provisioning additional resources to handle the load, ensuring that the application remains responsive and available.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Benefits of IaC
&lt;/h2&gt;

&lt;p&gt;Infrastructure as Code (IaC) offers numerous benefits that extend beyond simply automating infrastructure management. By leveraging IaC, organizations can achieve greater efficiency, reliability, and scalability in their DevOps processes. Let's explore some of the key benefits of IaC, including reduced errors, cost efficiency, disaster recovery, version control, and reusability.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Reduced Errors&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;One of the most significant advantages of IaC is the reduction of human errors. Manual infrastructure management often involves repetitive tasks that can lead to mistakes, especially in complex environments. With IaC, these tasks are automated, ensuring that infrastructure is provisioned and configured consistently every time. This consistency minimizes the risk of misconfigurations, which can lead to system failures or security vulnerabilities.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: Consider a scenario where multiple servers need to be configured with identical settings. Manually setting up each server increases the likelihood of discrepancies, but with IaC, you can automate this process, guaranteeing uniformity across all servers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Cost Efficiency&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;IaC can significantly reduce costs by optimizing resource management. Traditional infrastructure often involves over-provisioning resources to handle peak loads, leading to wasted resources and higher costs. With IaC, infrastructure can be dynamically scaled based on actual demand, ensuring that resources are allocated efficiently. This not only reduces costs but also improves the overall utilization of cloud services.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: Instead of running multiple servers at full capacity 24/7, IaC allows you to scale up resources during peak hours and scale down during off-peak times, saving on cloud costs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Disaster Recovery&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;IaC plays a crucial role in disaster recovery by enabling quick and reliable restoration of infrastructure. In the event of a system failure or data loss, IaC scripts can be used to re-provision infrastructure in a matter of minutes, ensuring minimal downtime. This capability is essential for maintaining business continuity, especially in critical environments where downtime can result in significant financial losses.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If a primary data center goes offline, IaC can automatically spin up a backup infrastructure in a different region, restoring services with minimal disruption.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  4. Easily duplicate an environment
&lt;/h4&gt;

&lt;p&gt;The same environment can be easily deployed on a different system in another location using the same IaC, as long as the infrastructure resources are available.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:For example, imagine a business’s regional branch has IaC to describe the whole branch’s enterprise environment, including servers, networking, and custom configurations. If the business opened another regional branch, they could use IaC to duplicate the exact same environment and quickly make the branch online and operational. IaC removes the repetitive manual steps and checklists that were needed in the past.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  5. &lt;strong&gt;Version Control&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Treating infrastructure as code allows you to leverage version control systems (VCS) like Git to track changes, collaborate on configurations, and maintain a history of infrastructure states. Version control enables teams to revert to previous configurations in case of issues, compare changes, and audit infrastructure modifications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: A team can roll back to a previous stable version of infrastructure code if a new deployment introduces issues, minimizing the impact on production environments.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  6. &lt;strong&gt;Reusability&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;IaC promotes reusability by allowing you to create modular templates or scripts that can be reused across multiple projects or environments. This not only saves time but also ensures that best practices are consistently applied. By reusing code, teams can quickly deploy new environments or replicate infrastructure across different regions with minimal effort.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: A reusable Terraform module for setting up a VPC (Virtual Private Cloud) can be applied to different environments, ensuring consistent network configurations across projects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  7. &lt;strong&gt;Easily duplicate an environment&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The same environment can be deployed on a different system in another location using the same IaC, as long as the infrastructure resources are available.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: Imagine a business’s regional branch has IaC to describe the whole branch’s enterprise environment, including servers, networking, and custom configurations. If the business opened another regional branch, they could use IaC to duplicate the exact same environment and quickly make the branch online and operational. IaC removes the repetitive manual steps and checklists that were needed in the past.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Challenges and Best Practices&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While Infrastructure as Code (IaC) offers significant benefits, it also comes with its own set of challenges. Additionally, to maximize the effectiveness of IaC, it's crucial to follow best practices. In this section, we'll discuss some of the common challenges associated with IaC, outline best practices for successful implementation, and introduce popular IaC tools, separated into agnostic and cloud-specific categories.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Challenges of IaC&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Learning Curve&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implementing IaC requires a solid understanding of both coding and infrastructure management. For teams new to IaC, the learning curve can be steep, especially when dealing with complex configurations and tools.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tool Sprawl&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With numerous IaC tools available, teams might face challenges in choosing the right tool for their needs. Additionally, managing multiple tools across different environments can lead to tool sprawl, making it difficult to maintain consistency.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Security Concerns&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IaC scripts often contain sensitive information, such as access keys and passwords. Ensuring that this information is securely managed and not exposed to unauthorized users is a critical challenge.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Debugging and Troubleshooting&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When issues arise, debugging IaC can be challenging, especially in large and complex infrastructures. Identifying the root cause of a problem may require in-depth knowledge of both the code and the infrastructure it manages.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Best Practices for IaC&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use Modular Code&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Break down IaC scripts into smaller, reusable modules. This approach makes the code more manageable, promotes reuse, and allows teams to apply consistent configurations across multiple environments.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Integrate with CI/CD Pipelines&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integrate IaC with Continuous Integration/Continuous Deployment (CI/CD) pipelines to automate testing and deployment of infrastructure changes. This ensures that changes are automatically validated and deployed, reducing the risk of errors.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Version Control Everything&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store all IaC scripts in a version control system (VCS) like Git. This allows teams to track changes, collaborate on configurations, and roll back to previous versions if needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Ensure Security Compliance&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use tools like HashiCorp Vault to securely manage sensitive information in IaC scripts. Regularly audit the scripts for security vulnerabilities and ensure compliance with industry standards.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Continuous Monitoring and Updates&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Regularly monitor IaC configurations and update them to accommodate new requirements or technologies. Continuous monitoring helps identify and address potential issues before they impact production environments.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Infrastructure as Code Tools&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Agnostic vs. Cloud-Specific IaC Tools&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;When choosing an IaC tool, it's essential to understand the difference between agnostic and cloud-specific tools. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Agnostic IaC Tools&lt;/strong&gt;: These tools are designed to work across multiple cloud providers and on-premises environments. They offer flexibility and are ideal for organizations that use a multi-cloud strategy or need to manage hybrid environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cloud-Specific IaC Tools&lt;/strong&gt;: These tools are tailored to a specific cloud provider, offering deep integration and leveraging the unique features of that provider. They are ideal for organizations that primarily operate within a single cloud ecosystem and want to take full advantage of the provider's offerings.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Category&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Tool Name&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Agnostic IaC Tools&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Terraform&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A widely-used tool that allows you to define and provision infrastructure across multiple cloud providers using a single configuration language.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Ansible&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A powerful automation engine that manages infrastructure and application deployment across various environments.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Pulumi&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Allows developers to use familiar programming languages like Python and JavaScript to define and deploy infrastructure across different cloud platforms.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cloud-Specific IaC Tools&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;AWS CloudFormation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A service by AWS that allows you to model and set up your Amazon Web Services resources using JSON or YAML templates.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Azure Resource Manager (ARM)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Microsoft Azure’s tool for managing infrastructure resources through templates, scripts, and APIs.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Google Cloud Deployment Manager&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A Google Cloud tool that allows you to manage cloud resources using declarative templates written in YAML.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;### Conclusion&lt;/p&gt;

&lt;p&gt;Infrastructure as Code (IaC) is not just a buzzword—it's a fundamental shift in how we manage and provision infrastructure in the modern DevOps landscape. By turning infrastructure management into a programmatic task, IaC allows organizations to automate, scale, and optimize their IT environments with unprecedented efficiency and consistency.&lt;/p&gt;

&lt;p&gt;Throughout this article, we've explored what IaC is, its critical role in transforming DevOps practices, and the numerous benefits it brings to the table, from reducing errors and costs to enabling rapid disaster recovery, version control, and reusability. We also discussed the challenges that come with adopting IaC and provided best practices to help you navigate these obstacles successfully.&lt;/p&gt;

&lt;p&gt;The integration of IaC into your DevOps pipeline is not just about improving operational efficiency—it's about enabling innovation. By freeing up time and resources previously spent on manual infrastructure tasks, your teams can focus on developing and delivering value-driven features faster and more reliably.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As you continue your journey with IaC, remember that the true power of this approach lies in its ability to bridge the gap between development and operations, fostering a culture of collaboration, automation, and continuous improvement.&lt;/strong&gt; Whether you’re a beginner just getting started or a seasoned professional looking to refine your practices, the principles and tools of IaC offer a clear path toward more agile and resilient infrastructure management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Call to Action&lt;/strong&gt;: Now is the time to explore IaC tools, experiment with them in your own environment, and start integrating them into your DevOps processes. Whether you choose a cloud-agnostic tool like Terraform or a cloud-specific solution like AWS CloudFormation, the key is to begin. The sooner you start, the sooner you’ll reap the benefits of a more automated, scalable, and reliable infrastructure.&lt;/p&gt;

&lt;p&gt;For those who want to dive deeper, consider exploring further resources, such as advanced tutorials, case studies, or even certifications in specific IaC tools, i have attached some resources below to help with that.&lt;br&gt;
 The world of IaC is vast and continually evolving, offering endless opportunities to learn, innovate, and transform the way we think about infrastructure.&lt;/p&gt;




</description>
      <category>aws</category>
      <category>devops</category>
      <category>terraform</category>
      <category>infrastructureascode</category>
    </item>
    <item>
      <title>Basic Linux Commands to Know: A Beginner's Guide</title>
      <dc:creator>benny fmo</dc:creator>
      <pubDate>Tue, 13 Aug 2024 11:55:35 +0000</pubDate>
      <link>https://dev.to/bennyfmo_237/basic-linux-commands-to-know-a-beginners-guide-41mf</link>
      <guid>https://dev.to/bennyfmo_237/basic-linux-commands-to-know-a-beginners-guide-41mf</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Linux is a powerful and flexible operating system used by developers, system administrators, cloud engineers, and IT professionals worldwide. Understanding basic Linux commands is essential for navigating the system, managing files, and performing administrative tasks. In this guide, we'll cover 15 essential Linux commands, explaining what each does and showing their outcomes.&lt;/p&gt;

&lt;p&gt;For this exercise, I'll be using &lt;strong&gt;Windows Subsystem for Linux (WSL)&lt;/strong&gt; running &lt;strong&gt;Ubuntu 22.04.3 LTS&lt;/strong&gt;. If you're not familiar with WSL or need help setting it up, you can find a detailed guide &lt;a href="https://www.howtogeek.com/744328/how-to-install-the-windows-subsystem-for-linux-on-windows-11/" rel="noopener noreferrer"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Command Structure in Linux
&lt;/h2&gt;

&lt;p&gt;Before diving into specific commands, it's important to understand the basic structure of a Linux command. A typical Linux command follows this format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;options] &lt;span class="o"&gt;[&lt;/span&gt;arguments]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;command&lt;/strong&gt;: This is the actual command you want to execute (e.g., &lt;code&gt;ls&lt;/code&gt;, &lt;code&gt;cd&lt;/code&gt;, &lt;code&gt;cp&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;options&lt;/strong&gt;: These modify the behavior of the command (e.g., &lt;code&gt;-l&lt;/code&gt; for &lt;code&gt;ls&lt;/code&gt; to list in long format).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;arguments&lt;/strong&gt;: These specify the targets for the command, like files or directories.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the command &lt;code&gt;ls -l /home&lt;/code&gt; lists the contents of the &lt;code&gt;/home&lt;/code&gt; directory in long format.&lt;/p&gt;




&lt;h2&gt;
  
  
  Using the &lt;code&gt;man&lt;/code&gt; Command
&lt;/h2&gt;

&lt;p&gt;Each &lt;/p&gt;

&lt;h2&gt;
  
  
  Linux
&lt;/h2&gt;

&lt;p&gt;command comes with a manual page (man page) that provides detailed information on how to use the command, including available options and examples. To access the man page for any command, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man command_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, to explore the options available for the &lt;code&gt;ls&lt;/code&gt; command, you would use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;man &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open a detailed manual where you can explore all the functionalities of the &lt;code&gt;ls&lt;/code&gt; command.&lt;/p&gt;




&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;pwd&lt;/li&gt;
&lt;li&gt;ls&lt;/li&gt;
&lt;li&gt;cd&lt;/li&gt;
&lt;li&gt;mkdir&lt;/li&gt;
&lt;li&gt;touch&lt;/li&gt;
&lt;li&gt;cp&lt;/li&gt;
&lt;li&gt;mv&lt;/li&gt;
&lt;li&gt;rm&lt;/li&gt;
&lt;li&gt;cd&lt;/li&gt;
&lt;li&gt;sudo&lt;/li&gt;
&lt;li&gt;cat&lt;/li&gt;
&lt;li&gt;grep&lt;/li&gt;
&lt;li&gt;echo&lt;/li&gt;
&lt;li&gt;find&lt;/li&gt;
&lt;li&gt;
top
&lt;a id="intro"&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  1. &lt;code&gt;pwd&lt;/code&gt; (Print Working Directory)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;pwd&lt;/code&gt; command displays the current working directory you're in. It's useful to know your location in the filesystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;/home/username&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujzyvm2exq6bk6l67pwo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujzyvm2exq6bk6l67pwo.png" alt="screenshot of pwd command in use" width="685" height="131"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="ls"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;ls&lt;/code&gt; (List Directory Contents)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;ls&lt;/code&gt; command lists the contents of a directory. It can display files, directories, and various details like permissions, ownership, and size.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;drwxr-xr-x 2 username username 4096 Aug 13 15:32 folder_name&lt;br&gt;
-rw-r--r-- 1 username username  220 Aug 13 15:32 file_name.txt&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5wf8n9gu6gcciowe6u3f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5wf8n9gu6gcciowe6u3f.png" alt="screenshot of ls command in use" width="800" height="159"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="cd"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;cd&lt;/code&gt; (Change Directory)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;cd&lt;/code&gt; command is used to change your current directory. You can navigate to any directory using the absolute or relative path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /home/username/Documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No output, just changes the directory to &lt;code&gt;/home/username/Documents&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8p83ooqvh6f6zccujzjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8p83ooqvh6f6zccujzjl.png" alt="screenshot of cd command in use" width="800" height="170"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="mkdir"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;code&gt;mkdir&lt;/code&gt; (Make Directory)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;mkdir&lt;/code&gt; command creates a new directory. You can specify the name of the directory you want to create.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;new_folder_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No output, just creates a directory named &lt;code&gt;new_folder_name&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsv8hq5f7psddz9s0bahw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsv8hq5f7psddz9s0bahw.png" alt="screenshot of mkdir command in use" width="800" height="137"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="touch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. &lt;code&gt;touch&lt;/code&gt; (Create a File)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;touch&lt;/code&gt; command is used to create an empty file or update the timestamp of an existing file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;new_file_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No output, just creates an empty file named &lt;code&gt;new_file_name&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69tj6147aub3hhk5df4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69tj6147aub3hhk5df4q.png" alt="screenshot showing how to use the move command" width="777" height="209"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="cp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. &lt;code&gt;cp&lt;/code&gt; (Copy Files/Directories)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;cp&lt;/code&gt; command copies files or directories from one location to another.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp &lt;/span&gt;file1.txt /home/username/Documents/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No output, just copies &lt;code&gt;file1.txt&lt;/code&gt; to the &lt;code&gt;/home/username/Documents/&lt;/code&gt; directory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbhzsqq3cgc8i7117ty6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbhzsqq3cgc8i7117ty6.png" alt="screenshot showing copy command in use" width="800" height="152"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="mv"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. &lt;code&gt;mv&lt;/code&gt; (Move/Rename Files)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;mv&lt;/code&gt; command moves or renames files or directories.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mv &lt;/span&gt;file1.txt new_file1.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No output, just renames &lt;code&gt;file1.txt&lt;/code&gt; to &lt;code&gt;new_file1.txt&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdq3qge8j45ci69iyfi4f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdq3qge8j45ci69iyfi4f.png" alt="screenshot showing how the mv command works in linux" width="800" height="218"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="rm"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8. &lt;code&gt;rm&lt;/code&gt; (Remove Files/Directories)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;rm&lt;/code&gt; command removes files or directories. Be cautious as this can permanently delete files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm &lt;/span&gt;unwantedfile.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No output, just deletes &lt;code&gt;unwantedfile.txt&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fclzzjpo6xy7gmjh84o55.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fclzzjpo6xy7gmjh84o55.png" alt="screeenshot showing how to use rm command" width="800" height="208"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="chmod"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  9. &lt;code&gt;chmod&lt;/code&gt; (Change File Permissions)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;chmod&lt;/code&gt; command changes the permissions of a file or directory. It’s useful for controlling who can read, write, or execute a file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;400 script.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No output, just changes the permissions of the file &lt;code&gt;script.sh&lt;/code&gt; to read only. You can type &lt;code&gt;ll&lt;/code&gt; or &lt;code&gt;ls -l&lt;/code&gt; to verify the permissions as shown below&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffadilzavnsnu4q0dnt8y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffadilzavnsnu4q0dnt8y.png" alt="screenshot showing the use of the chmod command" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="sudo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  10. &lt;code&gt;sudo&lt;/code&gt; (Admin privileges)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;sudo&lt;/code&gt; command in Linux allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. It stands for "Superuser Do" and is commonly used to perform tasks that require administrative or root privileges.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;sudo apt update&lt;/code&gt; refreshes the list of available packages and versions. &lt;code&gt;sudo&lt;/code&gt; is needed because this command updates system files that require administrative privileges without which permission will be denied as shown on the screenshot below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwfjvkxe4ur5ceuvmxtp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwfjvkxe4ur5ceuvmxtp.png" alt="screenshot showing the use of the sudo command" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="cat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  11. &lt;code&gt;cat&lt;/code&gt; (Concatenate and Display File Content)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;cat&lt;/code&gt; command displays the content of a file. It can also concatenate multiple files and display them together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;file_name.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Displays the contents of &lt;code&gt;file_name.txt&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza44ma2ft0d38j82xcaa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza44ma2ft0d38j82xcaa.png" alt="screenshot showing how to use the cat command on linux" width="800" height="141"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="grep"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  12. &lt;code&gt;grep&lt;/code&gt; (Search Text)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;grep&lt;/code&gt; command searches for a specific pattern of text within files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s2"&gt;"search_term"&lt;/span&gt; file2.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Displays the lines containing the string &lt;code&gt;search_term&lt;/code&gt; in &lt;code&gt;file2.txt&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6528nh3uaf7bbaxsntlg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6528nh3uaf7bbaxsntlg.png" alt="screenshot showing how to use the grep command on linux" width="800" height="138"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="echo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  13. &lt;code&gt;echo&lt;/code&gt; (Display a Line of Text)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;echo&lt;/code&gt; command outputs the specified text or variables to the terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello, World!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Displays the text &lt;code&gt;Hello, World!&lt;/code&gt; in the terminal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqpnebpuf7mualr4mgiw0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqpnebpuf7mualr4mgiw0.png" alt="screen shot showing the echo command in use" width="800" height="117"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="find"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  14. &lt;code&gt;find&lt;/code&gt; (Search for Files and Directories)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;find&lt;/code&gt; command searches for files and directories within a specified directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find /home/username/Documents &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.txt"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Lists all &lt;code&gt;.txt&lt;/code&gt; files in &lt;code&gt;/home/username/Documents&lt;/code&gt; and its subdirectories. A clear example is shown on the image below.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xfa73dy447qc4ahi30t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xfa73dy447qc4ahi30t.png" alt="screenshot showing how to use the find command on the linux terminal" width="800" height="141"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a id="top"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  15. &lt;code&gt;top&lt;/code&gt; (Display System Processes)
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;top&lt;/code&gt; command provides a real-time view of running processes and system resource usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;top
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Displays a dynamic view of system processes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhizmpgb57n3crbtxybj1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhizmpgb57n3crbtxybj1.png" alt="screenshot showing how to use the top command on linux" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;These basic Linux commands are essential tools for anyone working in a Linux environment. Mastering them will make navigating and managing your system more efficient. As you become more comfortable with these commands, you'll be able to perform more complex tasks with ease. Remember to use the &lt;code&gt;man&lt;/code&gt; command to explore the full capabilities of each command.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;1.&lt;a href="https://dev.to/devteam/how-to-write-a-high-quality-post-on-dev-3me0"&gt;&lt;strong&gt;How to write a high quality post on DEV&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.&lt;a href="https://youtu.be/ROjZy1WbCIA?si=U-Zz6wysW3ImtTTC" rel="noopener noreferrer"&gt;&lt;strong&gt;Youtube Linux Operating System - Crash Course for Beginners by freecodecamp&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet" rel="noopener noreferrer"&gt;&lt;strong&gt;Dev post formatting markdown cheat sheet on github&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>linux</category>
      <category>ubuntu</category>
      <category>devops</category>
      <category>bash</category>
    </item>
    <item>
      <title>hello devs!!</title>
      <dc:creator>benny fmo</dc:creator>
      <pubDate>Tue, 13 Aug 2024 11:03:51 +0000</pubDate>
      <link>https://dev.to/bennyfmo_237/hello-devs-26eb</link>
      <guid>https://dev.to/bennyfmo_237/hello-devs-26eb</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo hello world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
