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.
What is Load Balancing?
Load balancing is the distribution of workloads across multiple servers to ensure consistent and optimal resource utilization. It is an essential aspect of any large-scale and scalable computing system, as it helps you to improve the reliability and performance of your applications.
Elastic Load Balancing:
Elastic Load Balancing (ELB) is a service provided by Amazon Web Services (AWS) that automatically distributes incoming traffic across multiple EC2 instances. ELB provides three types of load balancers:
Application Load Balancer (ALB): This type of load balancer operates at the application layer (Layer 7) of the OSI model. It is best suited for distributing HTTP and HTTPS traffic and provides advanced routing capabilities. ALB allows you to route traffic based on content, host, or path, making it suitable for applications with multiple services running on the same set of servers.
Network Load Balancer (NLB): NLB operates at the transport layer (Layer 4) and is designed to handle TCP, UDP, and TLS traffic. It is well-suited for scenarios that require high performance and low latency. NLB is often used for applications that rely on the ability to maintain a consistent connection, such as gaming applications or Voice over IP (VoIP) services.
Classic Load Balancer (CLB): This is the older generation of load balancers on AWS. While it is still supported, it is recommended to use ALB or NLB for new applications. CLB can distribute traffic at both the application and transport layers but lacks some of the advanced features provided by ALB and NLB.
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 the number of instances to be launched, can you find it? :)
You can go one step ahead and create an auto-scaling group
Go to EC2 launch templates in the EC2 service and click on Create a launch template.
Give your desired name.
Select the relevant image.
Select the instance type (t2.micro)
Select a subnet if desired and skim through other settings until you reach the advanced details.
Here, you need to update the shell script for docker and Jenkins installation.
Finally, click on create a Launch template and a new template will be created.
It's time to launch an instance based on our template. Follow the instructions as showed in the image.
Make sure to enter the number of instances you want to create.
Finally, our instances are created based on the template we created earlier.
You can go one step ahead and create an auto-scaling group
Follow the steps in the images.
Give your desired naming.
Select the template which we created earlier.
For "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, such as 2.
For "Scaling policies", you 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.
Choose "Create Auto Scaling Group" to create the auto-scaling group.
Autoscaling 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. below two new instances launched by auto-scaling group.
Task 3:
launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.
Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name also do it for 2nd instance which includes " TrainWithShubham Community is Super Awesome :) ".
Copy the public IP address of your EC2 instances.
Open a web browser and paste the public IP address into the address bar.
You should see a webpage displaying information about your PHP installation.
Create 2 t2.micro instances (follow the same steps as did in the earlier tasks).
In the advanced details add the shell script to install apache2 server.
Here, the 2 instances are created.
Task 4:
Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
Add EC2 instances which you launch in task-1 to the ALB as target groups.
Verify that the ALB is working properly by checking the health status of the target instances and testing the load balancing capabilities.
Click on "Load Balancers" in the left-hand navigation menu and then click the "Create Load Balancer" button.
Select "Application Load Balancer" as the load balancer type and click "Create".
Configure the load balancer settings, such as name, listener, security group, and availability zones. For the listener, you can choose HTTP or HTTPS, depending on your application's requirements.
Configure Security groups. Create one specifically for this.
Now select the one we created.
In the routing section we need to add our atrget group that includes our instances.
The purpose is to register these targets on our load balancer.
This means it is not associated yet.
Selecting the target group.
Finally create the load balancer.
Confirming and adding the load balancer targets.
Here, now take the DNS and see if our instances are connected on the browser.
Finally Done.
Thankyou for reading it was a long one.