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:)"
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