Nicholas Carey
Nicholas Carey

Reputation: 74345

How Do I Attach an ASG to an ALB Target Group?

In AWS' Cloudformation, how do I attach an Autoscaling Group (ASG) to an Application Load Balancer Target Group?

There does not appear to be any direct way to do that directly in a Cloudformation Template (CFT), though it it possible using the AQWS CLI or API. The AWS::ElasticLoadBalancingV2::TargetGroup resource only offers these target types:

Upvotes: 7

Views: 7476

Answers (1)

Nicholas Carey
Nicholas Carey

Reputation: 74345

That is because, apparently, one does not attach an ASG to a target group; instead, one attaches a target group or groups to an ASG.

Seems a little backwards to me, but I'm sure it has to do with the ASG needing to register/deregister its instances as it scales in and out.

See the documentation for the AWS::AutoScaling::AutoScalingGroup resource for details.

Example:

TargetGroup:
  Type: AWS::ElasticLoadBalancingV2::TargetGroup
  Properties:
    VpcId: !Ref VPC
    TargetType: instance
    Port: 80
    Protocol: HTTP

AutoScalingGroup: 
  Type: AWS::AutoScaling::AutoScalingGroup
  Properties: 
    AvailabilityZones: !GetAZs !Ref "AWS::Region"
    MaxSize: "3"
    MinSize: "1"
    TargetGroupArns:
      - !Ref TargetGroup

Upvotes: 15

Related Questions