Day 40 AWS EC2 Automation ☁

Day 40 AWS EC2 Automation ☁

Day 40 of #90daysofdevops

Hey Techies! Welcome to this blog

In this blog, we are going to start AWS EC2 Automation ☁

Automation in EC2:

Amazon EC2 or Amazon Elastic Compute Cloud can give you secure, reliable, high-performance, and cost-effective computing infrastructure to meet demanding business needs.

Launch template in AWS EC2:

  • You can make a launch template with the configuration information you need to start an instance. You can save launch parameters in launch templates so you don't have to type them in every time you start a new instance.

  • For example, a launch template can have the AMI ID, instance type, and network settings that you usually use to launch instances.

  • You can tell the Amazon EC2 console to use a certain launch template when you start an instance.

Instance Types:

Amazon EC2 has a large number of instance types that are optimised for different uses. The different combinations of CPU, memory, storage and networking capacity in instance types give you the freedom to choose the right mix of resources for your apps. Each instance type comes with one or more instance sizes, so you can adjust your resources to meet the needs of the workload you want to run.

AMI:

An Amazon Machine Image (AMI) is an image that AWS supports and keeps up to date. It contains the information needed to start an instance. When you launch an instance, you must choose an AMI. When you need multiple instances with the same configuration, you can launch them from a single AMI.

Task1:

  • Create a launch template with Ubuntu 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.

    Sure, I can guide you through creating a launch template with Amazon Linux 2 AMI and t2.micro instance type, setting up Jenkins and Docker.

    Step 1: Create a Launch Template:

    1. Open the AWS Management Console.

    2. Navigate to EC2:

      • Click on "Services" in the upper left corner.

      • Under "Compute," select "EC2."

    3. Create a Launch Template:

      • In the EC2 Dashboard, on the left navigation pane, click on "Launch Templates."

  • Click the "Create launch template" button.

    1. Configure your Launch Template:
  • Choose the appropriate Amazon Machine Image (AMI), for instance, Ubuntu.

  • Choose the instance type as t2.micro.

  • In the "User data" section, you can provide scripts for Jenkins and Docker setup.

      #!/bin/bash

          # For update
          sudo apt update -y
          sudo apt install openjdk-11-jre-headless -y
          java -version 2>/home/ubuntu/jenkins_output.txt

          # For install Jenkins
          curl -fsSL https://pkg.jenkins.io/debian/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 binary/ | sudo tee \
            /etc/apt/sources.list.d/jenkins.list > /dev/null
          sudo apt-get update -y
          sudo apt-get install jenkins -y

          sudo systemctl enable jenkins
          sudo systemctl start jenkins
          sudo systemctl status jenkins >>/home/ubuntu/jenkins_output.txt

          # For install Docker
          sudo apt install docker.io -y
          sudo systemctl enable docker
          docker --version  2>/home/ubuntu/docker_output.txt
          sudo systemctl start docker >>/home/ubuntu/docker_output.txt
          sudo usermod -aG docker $USER
          sudo gpasswd -a $USER docker
  1. Save the Launch Template:
  • Click on "Launch instance from template."

Launch Instances using the Launch Template:

  1. Navigate to Instances:

    • In the EC2 Dashboard, on the left navigation pane, click on "Instances."
  2. Launch Instances:

    • Click the "Launch Instance from Template" button.

    • Select your created launch template.

    • You should find an option to specify the number of instances to launch. It might be labeled as "Number of instances" or something similar, depending on the AWS console interface at the time of use.

  • Proceed with the instance launch.

Create an Auto Scaling Group:

  1. Navigate to Auto Scaling Groups:

    • In the EC2 Dashboard, on the left navigation pane, click on "Auto Scaling Groups."
  2. Create an Auto Scaling Group:

    • Click the "Create Auto Scaling group" button.
  3. Configure Auto Scaling Group:

    • Choose your created launch template.

    • Configure the desired minimum, maximum, and desired capacity for the group.

    • Configure scaling policies based on your requirements. For instance, you can set up scaling policies based on CPU utilization to automatically scale in or out.

  4. Complete the Auto Scaling Group Setup:

    • Follow the prompts to complete the setup, including configuring notifications, tags, etc.

    • Click on "Create Auto Scaling group" to create the group.

By setting up an Auto Scaling group, your instances will automatically scale in and out based on the specified policies, ensuring that your application can handle varying levels of traffic without manual intervention.

That's it! You've just completed the task. 🎉

Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Happy Learning!

~kritika :)

Connect with me: linkedin.com/in/kritikashaw