Day 40 : AWS EC2 Automation ☁

Day 40 : 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.

Also, if you know a few things, you can automate many things.

Read from here

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.

Read more from here

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.

Read from here

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 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.

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

Creating a Launch Template and Launching Instances

  1. Create a Launch Template:

    • Login into AWS Console and search for "EC2".

    • Now click on Launch Templates(Left side corner).

    • Click on Create launch template(Orange button).

    • Enter a name (e.g., DevopsTemplate) and a description for the template.

    • For Amazon Machine Image (AMI), Click on Quick start and choose Ubuntu.

    • For Instance type, choose t2.micro.

    • Select or create a security group.

    • In the Advanced Details section, paste the user data script for installing Jenkins and Docker.

Here's an example of a user data script for setting up Jenkins and Docker:

#!/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 Create launch template.
  1. Launch Instances Using the Launch Template:

    • In the Amazon EC2 console, click on Create launch instance (orange button).

    • Select the launch template you created.

    • Specify the number of instances you want to launch (e.g., 2).

    • Configure other settings such as VPC, subnet, and security group as desired.

    • Choose Launch instances.

    • Verify that the instances are running in the Instances section.

Creating an Auto Scaling Group

An Auto Scaling group (ASG) is a collection of EC2 instances that are treated as a logical unit for automatic scaling and management. ASGs automatically adjust the number of instances based on demand, ensuring your application maintains optimal performance and cost-efficiency.

Steps to Create an Auto Scaling Group:

  1. Navigate to Auto Scaling Groups:

    • In the left navigation pane, choose Auto Scaling Groups.

    • Click Create Auto Scaling group.

  1. Configure the Auto Scaling Group:

    • Enter a name (e.g., DJScaling).

    • Choose the launch template created earlier, Specify the version (default to the latest version).

  2. Configure Network and Load Balancer:

    • Select the VPC and subnets for the instances.

    • Attach a new load balancer if required.

    • Create a target group for the load balancer.

  1. Set Group Size and Scaling Policies:

    • Desired capacity: 3

    • Minimum capacity: 1

    • Maximum capacity: 5

    • Configure scaling policies based on metrics such as CPU utilization.

  2. Finalize and Create the Auto Scaling Group:

    • Add notifications and tags if needed.

    • Review the configuration.

    • Click Create Auto Scaling group.

Thankyou for reading !!!!!