Sub topic 2
Target Groups and Registering Targets
Assume you know basic EC2, VPC, HTTP, and AWS CLI concepts. A target group is a named set of destinations, such as EC2 instances, IP addresses, or Lambda functions. A load balancer sends traffic to healthy targets in the selected group.
Registering targets and checking health
An Application Load Balancer (ALB) listener forwards requests to a target group. The group defines the protocol, port, target type, and health-check settings. Register an instance only after its security group allows traffic from the load balancer’s security group.
aws elbv2 create-target-group \
--name web-tg \
--protocol HTTP \
--port 80 \
--vpc-id vpc-0123456789abcdef0 \
--target-type instance \
--health-check-path /health
aws elbv2 register-targets \
--target-group-arn "$TG_ARN" \
--targets Id=i-0123456789abcdef0A health check periodically sends a request to the configured path and port. A target becomes healthy when it returns an accepted response within the timeout, for the required number of successful checks. It becomes unhealthy after enough consecutive failures. Common causes include an incorrect path, an application that starts too slowly, a blocked security-group rule, or a service listening on the wrong port.
TLS termination and traffic distribution
TLS termination means the load balancer decrypts HTTPS traffic before forwarding it. Attach an AWS Certificate Manager (ACM) certificate to an HTTPS listener. The certificate must cover the requested hostname and exist in the AWS Region containing the load balancer. You can then forward HTTP inside a protected VPC, or use HTTPS to the targets when encryption is required end to end.
Cross-zone load balancing lets a load balancer use healthy targets in other Availability Zones. It can improve distribution when zones contain different numbers of targets. When a target is removed, deregistration delay, also called connection draining, lets existing connections finish before new requests stop. Set the delay to match request duration, but avoid long delays that slow scale-in.
Instance blueprints and capacity limits
A launch template is a reusable blueprint for EC2 instances. It can specify the AMI, instance type, IAM role, security groups, user data, and storage. An Auto Scaling group (ASG) uses that template to maintain a desired number of instances across subnets.
The ASG’s minimum is the lowest capacity, maximum is the upper limit, and desired capacity is the current target. Attach the ASG to the target group so new instances register automatically and unhealthy instances can be replaced.
Exercise
Why might an instance be running but receive no requests?
Show answer
It may be unhealthy, not registered in the target group, in a subnet or zone excluded from the load balancer, or blocked by security-group rules.