Provision an Load Balancer via AWS CLI.
1. Create alb with 2 subnets in 2 Azs
aws elbv2 create-load-balancer --name my-load-balancer \
--subnets subnet-0e3f5cac72EXAMPLE subnet-081ec835f3EXAMPLE \
--security-groups sg-07e8ffd50fEXAMPLE
--ip-address-type dualstack
Output (arn of the Load Balancer):
arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/my-load-balancer/1234567890123456
2. Create Target Group
aws elbv2 create-target-group --name my-targets
--protocol HTTP
--port 80 \
--vpc-id vpc-0598c7d356EXAMPLE
--ip-address-type [ipv4 or ipv6]
Output (arn of Target Group):
arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/1234567890123456
3. Register the instances with the target group
aws elbv2 register-targets --target-group-arn targetgroup-arn \
--targets Id = i-0abcdef1234567890 Id = i-1234567890abcdef0
4. Create a listener for the Load Balancer with default rule that forwards requests to the Target Group
aws elbv2 create-listener --load-balancer-arn loadbalancer-arn \
--protocol HTTP --port 80 \
--default-actions Type=forward, TargetGroupArn = targetgroup-arn
Output (arn of the listener):
arn:aws:elasticloadbalancing:us-east-2:123456789012:listener/app/my-load-balancer/1234567890123456/1234567890123456
5. Verify the health of the registered targets for your target group
aws elbv2 describe-target-health --target-group-arn targetgroup-arn
6. Add an HTTPS listener
First, Create or import the certificate using AWS Certificate Manager (ACM) and:
aws elbv2 create-listener --load-balancer-arn loadbalancer-arn \
--protocol HTTPS --port 443 \
--certificates CertificateArn = certificate-arn \
--default-actions Type = forward, TargetGroupArn = targetgroup-arn
Delete the ELB
aws elbv2 delete-load-balancer --load-balancer-arn loadbalancer-arn
aws elbv2 delete-target-group --target-group-arn targetgroup-arn