Load Balancing
Elastic Load Balancing
Last updated
Was this helpful?
Elastic Load Balancing
Last updated
Was this helpful?
In this project we are going to use Amazon EC2 Auto Scaling that should distribute traffic among instances
Over all the code sets up an Auto Scaling group with a desired capacity of 1, minimum size of 1, and a maximum size of 2. Instances will be launched in two availability zones in the us-east-2
region, and their health will be monitored using EC2 status checks. The specifics of the instance configuration are determined by the referenced Launch Configuration MyLaunchConfiguration
--> SHIP YAML -->
---
We define an AWS CloudFormation resource for an Auto Scaling group
AvailabilityZones
: Specifies the availability zones where the instances in the Auto Scaling group will be launched. In this example, it will launch instances in both "us-east-2a" and "us-east-2b".
MinSize: "1"
: Specifies the minimum number of instances that should be maintained in the Auto Scaling group. In this case, it's set to 1, which means there should always be at least one instance running.
MaxSize: "2"
: Specifies the maximum number of instances that the Auto Scaling group can scale up to. In this case, it's set to 2, meaning the group can have a maximum of two instances running simultaneously. We can change that depend the scenario
DesiredCapacity: "1"
: Specifies the desired number of instances in the Auto Scaling group
HealthCheckType: EC2
: Specifies the type of health check used for the instances in the Auto Scaling group. In this case, it's set to "EC2," which means that the health of instances will be determined based on EC2 status checks.
LaunchConfigurationName: !Ref MyLaunchConfiguration
: References the name of the AWS Launch Configuration resource (MyLaunchConfiguration
) that defines the configuration settings for the instances launched by the Auto Scaling group. This Launch Configuration resource will specify details like the AMI, instance type, security groups, and other launch parameters.
---
Increased the MinSize
to 2 and MaxSize
to 4, which means our Auto Scaling group will ensure that at least 2 instances are always running, and can scale up to 4 instances if needed at anytime.
Created an Application Load Balancer (MyLoadBalancer
) in three subnets spanning different availability zones. This setup ensures high availability and fault tolerance.
We created a Target Group with an HTTP health check on the default route "/"
. The health check ensures that traffic is routed only to healthy instances.
To do
Can be added to the UserData
section in the main configuration yaml if needed. ( ELB handles the distribution of incoming traffic to multiple instances without needing Elastic IPs)
MyEIP
creates an Elastic IP address (EIP) using the AWS CloudFormation
MyLambdaExecutionRole
resource creating an IAM role which is going to be used by the Lambda function we will create
AssumeRolePolicyDocument
will define AWS Lambda service
MyLambdaFunction
resource will create a Lambda function using the latest Node.js
MyEIPAssociation
resource sends a request to a specified ServiceToken
(ARN)
Should have the AmazonEC2FullAcces
attached
Done:
Done:
External Health checks and Analytics
Taking the server down to test external health checks:
( Can add if required, depends the project)
-->
Tested? =