Table of contents
Today I have covered,
What is AWS EC2, Features, Pricing of AWS, and EC2 Launch template?
How to Create Launch Instance Template and Auto-Scaling?
What is AWS EC2?
- Amazon Elastic Compute Cloud (Amazon EC2) provides on-demand, scalable computing capacity in the
Amazon Web Services (AWS) Cloud
. UsingAmazon EC2
reduces hardware costs so you can develop and deploy applications faster. You can use Amazon EC2 to launch as many or as fewvirtual servers
as you need, configure security and networking, and manage storage. You can add capacity (scale up) tohandle compute-heavy tasks
, such as monthly or yearly processes, or spikes in website traffic.When usage decreases, you can reduce capacity (scale down) again
.
Features of Amazon EC2:
Amazon EC2 provides the following high-level features:
Instances: called as
Virtual servers
.Amazon Machine Images (AMIs): Preconfigured templates for your instances that package the components you need for your server (including the operating system and additional software).
Instance types: Various configurations of CPU, memory, storage, networking capacity, and graphics hardware for your instances.
Key pairs: Secure login information for your instances. AWS stores the public key and you store the private key in a secure place.
Instance store volumes: Storage volumes for temporary data that is deleted when you stop, hibernate, or terminate your instance.
Amazon EBS volumes: Persistent storage volumes for your data using Amazon Elastic Block Store (Amazon EBS).
Regions, Availability Zones, Local Zones, AWS Outposts, and Wavelength Zones: Multiple physical locations for your resources, such as instances and Amazon EBS volumes.
Security groups: A virtual firewall that allows you to specify the protocols, ports, and source IP ranges that can reach your instances and the destination IP ranges to which your instances can connect.
Elastic IP addresses: Static IPv4 addresses for dynamic cloud computing.
Tags: Metadata that you can create and assign to your Amazon EC2 resources.
Virtual private clouds (VPCs): Virtual networks you can create that are logically isolated from the rest of the AWS Cloud. You can optionally connect these virtual networks to your own network.
AWS EC2 Pricing:
Instance | CPU | Memory (GiB) | Storage (GB) | Linux On-Demand cost |
t2.micro | 1 | 1 | EBS only | $0.0116 per Hour |
t2.small | 1 | 2 | EBS only | $0.023 per Hour |
t2.medium | 2 | 4 | EBS only | $0.0464 per Hour |
t2.large | 2 | 8 | EBS only | $0.0928 per Hour |
t2.xlarge | 4 | 16 | EBS only | $0.1856 per Hour |
t2.2xlarge | 8 | 32 | EBS only | $0.3712 per Hour |
m5.large | 2 | 8 | EBS only | $0.096 per Hour |
m5.xlarge | 4 | 16 | EBS only | $0.192 per Hour |
m5.2xlarge | 8 | 32 | EBS only | $0.384 per Hour |
Instance type: The type of instance to launch. An instance type defines the hardware of the host computer used for your instance. Each instance type provides different computing and memory capabilities. You can select an instance type based on the amount of memory and computing power that you need for the application or software that you plan to run on your instance.
AWS EC2 Instance Template:
You can create a launch template that contains the
configuration information
to launch an instance. You can use launch templates to storelaunch parameters
so that you do not have to specify them every time you launch an instance.For example, a launch template can contain the AMI ID, instance type, and network settings that you typically use to launch instances. When you launch an instance using the Amazon EC2 console, an AWS SDK, or a command line tool, you can specify the launch template to use.
Amazon Machine Image (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.
AWS Auto Scaling:
- Amazon EC2 Auto Scaling helps you maintain
application availability
and lets you automaticallyadd
orremove EC2 instances
usingscaling policies
that you define. Dynamic or predictive scaling policies let you add or remove EC2 instance capacity to service established or real-time demand patterns. Thefleet management
features ofAmazon EC2 Auto Scaling
help maintain the health and *availability of your fleet.
Task 1:
Create a launch template with Amazon Linux 2 AMI and t2.micro instance type with Jenkins and Docker setup using user data script.
- Step 1: Go to the EC2 service and click on Launch Templates under INSTANCES and hit Create launch template.
- Step 2: Select Application and OS as Amazon Linux 2 and t2.micro as instance type.
- Step 3: Select Create a new key pair and give a name to it and download it and Network type as VPC and Subnet as Public Subnet.
- Step 4: Click on Advanced details and paste the below script in User data and click on Create launch template.
#!/bin/bash
sudo apt update
sudo apt install openjdk-8-jdk
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 update
sudo apt install jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
- Step 5: Go to the EC2 service and click on Auto Scaling Groups under Auto Scaling and hit Create Auto Scaling group.
Create 3 Instances using Launch Template, there must be an option that shows the number of instances to be launched using Auto Scaling Group.
- Step 1: Go to the EC2 service and click on Auto Scaling Groups under Auto Scaling and hit Create Auto Scaling group.
- Step 2: Select Network as VPC and Subnet as Public Subnet and click on Next.
- Step 3: Here we are not using Load Balancer so click on Next.
- Step 4: Configure group size and scaling policies and click on Next and skip notifications and tags we have created the Auto Scaling group successfully.
- Step 5: Go to the EC2 service and click on Auto Scaling Groups under Auto Scaling and click on Auto Scaling group and click on Edit and change the Desired capacity to 3 and click on Update.
- Step 6: So After that, we delete the Auto Scaling group and it will delete all the instances.