AWS EC2 Automation ☁

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:

In AWS EC2, a launch template is a resource that allows you to specify all the configuration details needed to launch an instance. It acts as a blueprint for creating instances with consistent settings and configurations. Launch templates simplify the process of launching instances by saving you time and ensuring consistency across your infrastructure.

Instance Types:

In AWS, Instance Types and AMIs (Amazon Machine Images) are important concepts when working with EC2 (Elastic Compute Cloud) instances. Let's explore each concept:

Instance Types: Instance types define the hardware configurations and capabilities of the virtualized servers in AWS EC2. Each instance type is optimized for specific workloads and provides a combination of CPU, memory, storage, and networking capacity. AWS offers a wide range of instance types, each designed for different use cases, performance requirements, and cost considerations.

Instance types are categorized into families based on their intended usage. Some common instance families include:

  1. General Purpose (e.g., t3, m5): These instances provide a balance of compute, memory, and network resources and are suitable for a wide range of workloads.

  2. Compute Optimized (e.g., c5, c6g): These instances are designed for CPU-intensive workloads, such as high-performance web servers, scientific modeling, and batch processing.

  3. Memory Optimized (e.g., r5, x1): These instances are optimized for memory-intensive workloads, such as in-memory databases, real-time big data processing, and analytics.

  4. Storage Optimized (e.g., i3, d3): These instances are designed for storage-intensive workloads, such as NoSQL databases, data warehousing, and distributed file systems.

  5. GPU Instances (e.g., p3, g4): These instances are equipped with powerful GPUs and are suitable for graphics-intensive workloads, machine learning, and video rendering.

AMI:

AMI (Amazon Machine Image): An AMI is a pre-configured template that contains the information required to launch an EC2 instance. It includes the operating system, application server, applications, and other software configurations. AMIs provide the foundation for creating EC2 instances and can be either Amazon-provided or custom-built.

Amazon offers a variety of AMIs, including those optimized for different operating systems (e.g., Amazon Linux, Ubuntu, Windows Server), specific software stacks (e.g., LAMP stack, Docker), and use cases (e.g., machine learning, gaming).

AUTOSCALING:

Autoscaling in AWS is a feature that allows you to automatically adjust the number of EC2 instances in an Amazon EC2 Auto Scaling group based on the demand of your application. Autoscaling helps ensure that you have the right amount of compute capacity to handle varying levels of traffic or workload without manual intervention. It helps maintain application availability, improve fault tolerance, and optimize costs by automatically scaling in and out based on predefined scaling policies.

Task1:

  • Create a launch template with Amazon Linux 2 AMI and t2.micro instance type with Jenkins and Docker setup

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

user data script

#installing jenkins and docker on Amazon Linux machine
#!/bin/bash
sudo yum update –y
sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
sudo amazon-linux-extras install java-openjdk11 -y
sudo dnf install java-11-amazon-corretto -y
sudo yum install jenkins -y
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo yum update -y
yum install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user

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

Create an auto-scaling group

I have used the Target-Tracking-scaling policy: This policy keeps a specified metric (such as CPU utilization or request count per target) at a target value. It adjusts the number of instances to maintain the target metric.

As I have mentioned desired capacity 1, so instance created only 1

Now I have changed desired capacity to 2

here you can see two instances

I hope you found this blog helpful. Feel free to leave your comments and share your thoughts below and, if you enjoyed this blog, consider sharing it with your network to help others discover the information shared here