Question:
when I try to create Autoscale group with Application load balancer with the following cloudformation yml file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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:)”
Answer:
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 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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 |