๐ Introduction:
In this blog, we will demonstrate how to create a launch template for Amazon Linux 2 with Jenkins and Docker setup, launch instances using the launch template, and even create an auto-scaling group.
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 optimized 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.
Task: 1
Create a launch template with Amazon Linux 2 AMI and t2.micro instance type with Jenkins and Docker setup.
Open the Amazon EC2 dashboard.
In the left navigation pane, choose Launch Templates click on Create launch template
- In the Create a Launch template page, enter a name for the launch template and enter the Template version.
- For Amazon Machine Image (AMI), choose Amazon Linux 2, For Instance type, choose t2.micro.
- Select a key pair & create or choose a security group
- In the Advanced Details section, paste the user data script for installing Jenkins and Docker in the User data field.
#!/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
- A template has been created
Create 3 Instances using Launch Template, there must be an option that shows the number of instances to be launched, can you find it?
- In the Amazon EC2 dashboard, choose Launch instance from templates
- Select the launch template that you just created
Specify the number of instances you want to launch in the Number of instances field. Choose the other configuration settings as desired, such as VPC, subnet, security group, and so on.
Choose Launch instances to launch the instances.
We can go one step ahead and create an auto-scaling group
In the left navigation pane, choose Auto Scaling Groups.
Choose Create Auto Scaling Group.
In the Create Auto Scaling Group page, enter a name for the auto-scaling group.
For the Launch Template, choose the launch template we created earlier.
Network choose the VPC and subnet you want the instances to launch in
For Load balancing, choose any option as per your requirement
- In the Group Size page, enter the desired capacity for the auto-scaling group
Scaling policies, we can choose to set up scaling policies based on various metrics such as CPU utilization, network in/out, and others. Choose the policy target tracking policy.
Final step review the configuration & click on Create Auto Scaling Group
Auto Scaling Group is created
After a few moments, the auto-scaling group will launch the desired number of instances based on the launch template and the configuration you specified
When the utilization increases or decreases, the instances are scaled up or down automatically, based on the criteria we have given.
๐ Conclusion :
In this blog, we cover how to create a launch template for Amazon Linux 2 with Jenkins and Docker setup, launch instances using the launch template, and even create an auto-scaling group., in the next blog we will cover AWS Advanced Topics.
Thank you for reading!
Contact me on Linkedin
Check out my GitHub for more resources ๐