Review the Auto Scaling group load-balancer association

Associate a load balancer with an Auto Scaling group when its workload needs traffic distribution.

Description

Attach an Auto Scaling group to its load balancer or target group when it serves requests that way. Queue workers may not need an attachment.

Potential impact

The load balancer cannot send requests to a new instance until it is registered.

Remediation

Use load_balancers for a Classic ELB or target_group_arns for an ALB or NLB. If Auto Scaling should replace instances that fail load-balancer checks, enable ELB health checks on the group.

Examples

The second example attaches the existing Classic ELB elb-1. Supply the referenced launch template and verify that the instance registers as healthy.

Before

hcl
resource "aws_autoscaling_group" "example" {
  availability_zones = ["us-east-1a"]
  desired_capacity   = 1
  max_size           = 1
  min_size           = 1

  launch_template {
    id      = aws_launch_template.foobar.id
    version = "$Latest"
  }
}

After

hcl
resource "aws_autoscaling_group" "example" {
  availability_zones = ["us-east-1a"]
  desired_capacity   = 1
  max_size           = 1
  min_size           = 1

  launch_template {
    id      = aws_launch_template.foobar.id
    version = "$Latest"
  }

  load_balancers = ["elb-1"]
}

References