我正在使用 linter 并且我的模板显示有效,但我的部署失败并出现“AWS::ElasticLoadBalancingV2::ListenerRule 验证异常”。 Cloud Formation 控制台中似乎没有任何地方可以进一步深入了解此异常。如何确定我的部署无效的原因?
云形成模板
Parameters:
Env:
Type: String
Mappings:
EnvMap:
sandbox:
...
Resources:
HttpsListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
Certificates:
- CertificateArn: !FindInMap [EnvMap, !Ref Env, CertificateArn]
DefaultActions:
- Type: forward
ForwardConfig:
# TODO: read all this stuff off HTTP listener
TargetGroupStickinessConfig:
Enabled: false
TargetGroups:
- TargetGroupArn:
!FindInMap [EnvMap, !Ref Env, LoadBalancerDefaultTargetArn]
Weight: 1
TargetGroupArn:
!FindInMap [EnvMap, !Ref Env, LoadBalancerDefaultTargetArn]
LoadBalancerArn: !FindInMap [EnvMap, !Ref Env, LoadBalancerArn]
Port: 443
Protocol: HTTPS
HttpsListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: forward
ForwardConfig:
TargetGroupStickinessConfig:
Enabled: false
TargetGroups:
- TargetGroupArn:
!FindInMap [EnvMap, !Ref Env, LoadBalancerRouteTargetArn]
Weight: 1
TargetGroupArn:
!FindInMap [EnvMap, !Ref Env, LoadBalancerRouteTargetArn]
Conditions:
- Field: path-pattern
PathPatternConfig:
Values:
- /*
Values:
- /*
ListenerArn: !Ref HttpsListener
Priority: 50000
错误
事件中的“状态原因”。
Resource handler returned message: "Invalid request provided: AWS::ElasticLoadBalancingV2::ListenerRule Validation exception" (RequestToken: 16bd4239-0d41-b16f-2963-b0a774009dfd, HandlerErrorCode: InvalidRequest)
最佳答案
尝试从 Conditions
键中删除 PathConfigPattern
:
HttpsListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: "forward"
ForwardConfig:
TargetGroupStickinessConfig:
Enabled: false
TargetGroups:
- TargetGroupArn: !FindInMap [ EnvMap, !Ref Env, LoadBalancerRouteTargetArn ]
Weight: 1
TargetGroupArn: !FindInMap [ EnvMap, !Ref Env, LoadBalancerRouteTargetArn ]
Order: 1
Conditions:
- Field: path-pattern
Values:
- "/*"
ListenerArn: !Ref HttpsListener
Priority: 50000
此外,请确保您的 EnvMap
map 如下所示:
Parameters:
Env:
Type: String
Default: sandbox
Mappings:
EnvMap:
sandbox:
LoadBalancerRouteTargetArn: "arn:aws:elasticloadbalancing:eu-west-1:111111111111:targetgroup/my-tg-1/222222222222"
prod:
LoadBalancerRouteTargetArn: "arn:aws:elasticloadbalancing:eu-west-1:333333333333:targetgroup/my-tg-2/444444444444"
关于validation - 调试 CloudFormation 验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70040373/