6

when I try to create Autoscale group with Application load balancer with the following cloudformation yml file

    LoadBalancer: 
      Type: AWS::ElasticLoadBalancingV2::LoadBalancer
      Properties: 
        Type: application
        Subnets: 
          Ref: VPCZoneIdentifier  

    AutoScalingGroup:
      Type: AWS::AutoScaling::AutoScalingGroup
      DependsOn: LoadBalancer
      Properties:
        AvailabilityZones: 
          Ref: "AvailabilityZones"
        Cooldown: 120
        DesiredCapacity:
          Ref: DesiredCapacityASG
        LaunchConfigurationName: 
          Ref: LaunchConfiguration
        MaxSize:
          Ref: MaxSizeASG
        MinSize:
          Ref: MinSizeASG
        LoadBalancerNames: 
          - Ref: "LoadBalancer"
        TargetGroupARNs:
          - !Ref TargetGroup

I got an error saying "Provided Load Balancers may not be valid. Please ensure they exist and try again. (Service: AmazonAutoScaling; Status Code: 400; Error Code: ValidationError; Request ID:)"

Yasser
  • 1,159
  • 1
  • 14
  • 19

2 Answers2

8

this error is happening because you used LoadBalancerNames for Application loadbalancer as it is noted here

to fix it : remove the LoadBalancerNames and keep TargetGroupARNs in the properties

LoadBalancerNames:
- Ref: "LoadBalancer"

so the yml file will be like :

    AutoScalingGroup:
      Type: AWS::AutoScaling::AutoScalingGroup
      DependsOn: LoadBalancer
      Properties:
        AvailabilityZones: 
          Ref: "AvailabilityZones"
        Cooldown: 120
        DesiredCapacity:
          Ref: DesiredCapacityASG
        LaunchConfigurationName: 
          Ref: LaunchConfiguration
        MaxSize:
          Ref: MaxSizeASG
        MinSize:
          Ref: MinSizeASG
        TargetGroupARNs:
          - !Ref TargetGroup
Yasser
  • 1,159
  • 1
  • 14
  • 19
  • It should be list of string. so it will be like - [ !Ref TargetGroup ] – Kavyesh Shah Jan 05 '21 at 17:30
  • @KavyeshShah it shouldn't be `[ !Ref TargetGroup ] ` as it's a yml file, the `-` already denotes list so, square brackets aren't necessary but in JSON they are – Blank Mar 22 '21 at 12:22
0

If you are using ansible ec2_asg module and reached here, replace load_balancers: with target_group_arns and pass the ARN of the Target Group.

Jobin Joseph
  • 177
  • 2
  • 3