Day 40 AWS EC2 Automation ☁

Day 40 AWS EC2 Automation ☁

Automation in EC2:

Amazon Elastic Compute Cloud (Amazon EC2) is a fundamental service within Amazon Web Services (AWS) that provides scalable and resizable compute capacity in the cloud. Essentially, it allows users to launch and manage virtual machines (VMs), known as "instances," to run applications and workloads. EC2 instances are commonly used for a wide range of tasks, from hosting websites and applications to running complex data analysis jobs.

Key features and concepts of Amazon EC2 include:

  1. Instances: These are virtual servers that can be configured with different CPU, memory, storage, and network capacities based on your needs. EC2 offers a variety of instance types optimized for different use cases.

  2. AMI (Amazon Machine Image): An AMI is a pre-configured template used to launch EC2 instances. AMIs contain the necessary information to launch an instance, including the operating system, software, and configuration settings.

  3. Instance Types: EC2 provides a range of instance types optimized for various workloads, such as general-purpose, compute-optimized, memory-optimized, and storage-optimized instances.

  4. Regions and Availability Zones: EC2 instances can be launched in different geographical regions worldwide, each consisting of multiple Availability Zones. This architecture provides redundancy and high availability for applications.

  5. Elastic IPs: Elastic IP addresses are static IP addresses that can be associated with EC2 instances. They are useful for ensuring that your instance retains the same IP address even after stopping and restarting.

  6. Security Groups: Security Groups act as virtual firewalls, controlling inbound and outbound traffic to and from EC2 instances. You can define rules to allow or deny specific types of traffic.

  7. Key Pairs: Key pairs are used for secure SSH (Secure Shell) access to EC2 instances. You create a key pair, and the private key is used to access the instance securely.

  8. EBS (Elastic Block Store): EBS provides scalable block storage volumes that can be attached to EC2 instances. These volumes are used for data storage and can be easily backed up and resized.

  9. Auto Scaling: Auto Scaling is a feature that allows you to automatically adjust the number of EC2 instances based on predefined scaling policies. This ensures your application can handle varying workloads efficiently.

  10. Load Balancers: AWS offers load balancing services such as Elastic Load Balancing (ELB) to distribute incoming traffic across multiple EC2 instances for better availability and fault tolerance.

EC2 is a fundamental building block of AWS and is widely used by businesses and developers to deploy, manage, and scale applications in the cloud. Its flexibility, scalability, and cost-effectiveness make it a core component of cloud computing solutions.

The below image depicts the lifecycle of an Instance:

Instance Sizes

Task1:

  • Create a launch template with Amazon Linux 2 AMI and t2.micro instance type with Jenkins and Docker setup (You can use the Day 39 User data script for installing the required tools.

  • Click on the launch template

  • Application and OS Images (Amazon Machine Image): Ubuntu

    Instance Type: t2.micro

    Advanced Details: Use the following script-

  •       #!/bin/bash
          sudo apt-get update -y
          sudo apt install openjdk-11-jre -y
          curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
            /usr/share/keyrings/jenkins-keyring.asc > /dev/null
          echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
            https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
            /etc/apt/sources.list.d/jenkins.list > /dev/null
          sudo apt-get update
          sudo apt-get install jenkins -y
          sudo systemctl enable jenkins
          sudo systemctl start jenkins
          sudo apt-get update
          sudo apt-get install docker.io -y
          sudo systemctl start docker
    

    Click on Create Launch Template.

    In the Launch Templates Dashboard, select the template you created and click on Actions. Select Launch Instance from the template.

    • Create 3 Instances using Launch Template, there must be an option that shows a number of instances to be launched,can you find it? :)

  • We can see that 3 instances are running.

    • You can go one step ahead and create an auto-scaling group, sounds tough?

Let’s create ASG(Auto Scaling Group) and make the process more automated depending on the usage.

On the left side of your screen, you can find Auto Scaling Groups.

  • Click on Create Auto Scaling Group.

    Step 1: Choose the launch template or configuration

    Auto Scaling group name: JenkinsDockerScaling

    Launch template: DockerJenkinsTemplate

    Version: 2

Click Next.

Step 2: Choose instance launch options

  • Select the availability zones and click on Next.

    Step 3: Configure advanced options

    Load balancing: Attach to a new load balancer

  • Let the other options be the default, and click on Next.

    Step 4*:* Configure group size and scaling policies

  • Desired capacity: 2

    Minimum capacity: 1

    Maximum capacity: 5

    Click on Next.

    Step 5: Add notifications

  • Step 6: Add Tags

  • When the utilization increases or decreases, the instances are scaled up or down automatically, based on the criteria you have given.

    In this blog, I have discussed how to automate EC2 instance creation using Launch Templates and Auto Scaling Groups. If you have any questions or would like to share your experiences, please leave a comment below. Don’t forget to read my blogs and connect with me on LinkedIn and let’s have a conversation.

  • If you have questions or experiences to share, please feel free to comment below. You can also connect with me on LinkedIn; my name there is Akash Singh. I'm open to suggestions and corrections to improve my blog.

    #Day38 #90daysofdevops

    Thank you for reading!

    Thank You! Stay Connected ☁️👩‍💻🌈

    Contact me at :

    LinkedIn: linkedin.com/in/akash-singh-48689a176

    E-mail: /

Did you find this article valuable?

Support Akash-DevOps by becoming a sponsor. Any amount is appreciated!