Creating a Highly-Available website in AWS
Git-Geetansh
Posted on May 2, 2024
1.Prerequisites:
AWS Account: You'll need an active AWS account with appropriate permissions to create EC2 instances, Application Load Balancers, Auto Scaling Groups, and related resources.
Basic Knowledge of AWS Services: Familiarity with EC2, Auto Scaling, Application Load Balancer, and related AWS services is recommended.
2.Aim:
The aim of this project is to create a highly available website infrastructure using AWS services including EC2 instances, Application Load Balancer, and Auto Scaling Group.
Ensure that the website remains accessible and responsive even during high traffic loads or in the event of instance failures.
Implement auto-scaling to automatically adjust the number of EC2 instances based on demand, optimizing costs and performance.
3.Resources Used: VPC(subnets, internet gateway, route tables) EC2, Security Groups, Load Balancer, Template, Auto Scaling Group.
4.Steps:
Set up VPC (Virtual Private Cloud): Create a VPC (Select an appropriate region of your choice ) to isolate your resources and provide network security.
points to remember:
When creating a VPC you will have two options - VPC only and VPC and more.
In a VPC-only scenario:
You create the VPC itself, but it doesn’t automatically include any subnets, internet gateways, or route tables.
You have to manually add subnets to the VPC, allocate IP addresses, and configure routing.
Here, we will be manually adding all the resources so as to get the underlying concepts and working of our architecture.
No internet gateway is automatically created, so instances within the VPC cannot directly access the internet.
VPC with More Options:
When you choose to create a VPC with more options, AWS automatically sets up additional components along with the VPC
You need to set up custom route tables to define how traffic flows within the VPC.
Create Subnets: Create subnets, one in each availability zone of the region selected.
points to remember -
CIDR block of the subnets should not overlap with each other, or it will show an error. you can use online available subnet calculator tool or simple use the arrows highlighted.
Create an Internet gateway and attach the gateway to the above vpc created.
Create Route tables:
create a route table and associate it with all 3 subnets that you created earlier.
also edit routes
Creating Security Groups:
Security Group for Application Load Balancer.
inbound rules:
Security group for EC2 fleet.
inbound rules
only inbound rules for security group for ec2 fleet is that it will receive traffic from security group of your load balancer.
Launch EC2 Instances:
Launch an EC2 instance, select the same region, VPC, any 1 subnet, Security group for EC2, and enable auto-allocation of public IP.
in the use data script, add the following script.
Create a template from the EC2 created, this template will be used to create your Auto Scaling group.
Create Application Load Balancer (ALB): Set up an ALB to distribute incoming traffic across multiple EC2 instances.
points to remember:
select security group created for ALB
select all the subnets
for target groups create a target group, add the created instance in the target group.
check your Elastic load balancer by copying its DNS name and pasting it to a browser, preferably in a new Cognito window.
your should see the Hello world page, along with private IP of your instance
Create Auto Scaling Group (ASG):
Configure an ASG to automatically adjust the number of EC2 instances based on demand
points to remember:
select the template we created earlier.
select the VPC and all the subnets
select the elastic load balancer option, and select the target group created above.
check the activity tab of your auto scaling group, it shows alerts regarding....well it's activities. instances will spin up in accordance with your Desired capacities.
refresh the tab where you pasted the DNS name. you should see the change in private ip addresses, that means the load balancer is working and distributing load to all EC2 instances.
Test High Availability: Conduct tests to ensure that your website remains accessible and responsive even during instance failures or high traffic loads.
try terminating instances, auto scaling group will automatically spin up more to take its place.
5.Conclusion:
By implementing the above steps, you have successfully created a highly available website infrastructure on AWS using EC2 instances, Application Load Balancer, and Auto Scaling Group.
Your website is now capable of handling varying levels of traffic and instances failures without affecting user experience.
Regular monitoring and optimization of your infrastructure will help ensure continued high availability and performance.
6.Clean-Up:
Once you have completed testing and are finished with your project, remember to clean up all resources to avoid unnecessary costs.
Terminate EC2 instances, delete Auto Scaling Group, remove Application Load Balancer, and delete any other associated resources.
Optionally, you may also want to delete the VPC and related networking resources if they are no longer needed.
Posted on May 2, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024