I am trying to create 2 listeners for the load balancer.
1st - HTTP for redirecting and 2nd - HTTPS for forwarding.
I am trying to achieve this via cf template. Everytime I execute the stack in console via design template, it is validated successfully. But when I try the same stack with aws cli, I get the following error.
An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved resource dependencies [ApplicationLoadBalancer] in the Resources block of the template
Following is the code sample for listener and LB.
"ApplicationLoadBalancer": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Condition": "NeedELB",
"Properties": {
"Subnets": [
{
"Fn::GetAtt": [
"VpcStack",
"Outputs.PublicSubnet1"
]
},
{
"Fn::GetAtt": [
"VpcStack",
"Outputs.PublicSubnet2"
]
}
],
"SecurityGroups": [
{
"Fn::GetAtt": [
"VpcStack",
"Outputs.ELBSecurityGroup"
]
}
],
"Tags": [
{
"Key": "Stack",
"Value": {
"Ref": "AWS::StackName"
}
},
{
"Key": "FargateCluster",
"Value": {
"Ref": "FargateECSCluster"
}
}
]
}
},
"LoadBalancerHTTPListener": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"DefaultActions": [
{
"Type": "redirect",
"RedirectConfig": {
"Host": "#{host}",
"Path": "/#{path}",
"Port": "443",
"Protocol": "HTTPS",
"Query": "#{query}",
"StatusCode": "HTTP_302"
}
}
],
"LoadBalancerArn": {
"Ref": "ApplicationLoadBalancer"
},
"Port": "80",
"Protocol": "HTTP"
},
"DependsOn": [
"ApplicationLoadBalancer"
]
},
"LoadBalancerListener": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Condition": "NeedELB",
"Properties": {
"DefaultActions": [
{
"Type": "forward",
"TargetGroupArn": {
"Ref": "DefaultTargetGroup"
}
}
],
"LoadBalancerArn": {
"Ref": "ApplicationLoadBalancer"
},
"Port": "443",
"Protocol": "HTTPS",
"Certificates": [
{
"CertificateArn": {
"Fn::If": [
"NeedTLSEndPoint",
{
"Ref": "SSLCertificateArn"
},
{
"Ref": "AWS::NoValue"
}
]
}
}
]
},
"DependsOn": [
"DefaultTargetGroup",
"ApplicationLoadBalancer"
]
}
Please help me out with the validation error. Thanks in advance.