[英]AWS listener cf template gives error in aws cli but is valid in console(design template)
I am trying to create 2 listeners for the load balancer. 我正在尝试为负载均衡器创建2个侦听器。
1st - HTTP for redirecting and 2nd - HTTPS for forwarding. 第一个-HTTP用于重定向,第二个-HTTPS用于转发。
I am trying to achieve this via cf template. 我试图通过cf模板实现这一目标。 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.
但是当我用aws cli尝试相同的堆栈时,我收到以下错误。
An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unresolved resource dependencies [ApplicationLoadBalancer] in the Resources block of the template
调用CreateStack操作时发生错误(ValidationError):模板格式错误:模板的Resources块中未解析的资源依赖项[ApplicationLoadBalancer]
Following is the code sample for listener and LB. 以下是侦听器和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.
提前致谢。
Is there a change in condition NeedELB
when you create from CLI? 从CLI创建时,
NeedELB
条件是否发生了变化? I see that resource LoadBalancerHTTPListener
depends on ApplicationLoadBalancer
which is created conditionally. 我看到资源
LoadBalancerHTTPListener
依赖于有条件创建的ApplicationLoadBalancer
。 If NeedELB
is false, stack might still try to create LoadBalancerHTTPListener
. 如果
NeedELB
为false,则堆栈可能仍会尝试创建LoadBalancerHTTPListener
。 Either way you should add that condition for LoadBalancerHTTPListener
. 无论哪种方式,您都应该为
LoadBalancerHTTPListener
添加该条件。
PS: Try updating your CLI. PS:尝试更新CLI。 Older CLI version can cause this.
较旧的CLI版本可能导致此问题。 Case in point resource-type-error-while-trying-to-use-cloudformation
点资源类型错误 - 尝试使用 - 形成的情况
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.