调试 CloudFormation 验证问题

问题描述 投票:0回答:2

我正在使用 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)
validation debugging aws-cloudformation
2个回答
0
投票

尝试从

PathConfigPattern
键中删除
Conditions

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
地图如下所示:

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"

0
投票

使用Cloud Trail,您会看到所有错误。 Cloud Trail 是 AWS 记录您账户中发生的所有事情的地方,包括 cloudformation 正在执行的任何操作。对于出现的问题,CloudTrail 中通常比 Cloudformation 模板中提供更好的提示。它通常会指出你的问题所在。

要使用 CloudTrail,请登录出现 cloudformation 错误的 AWS 账户控制台,然后登录“Cloud Trail”服务,然后单击“事件历史记录”。单击右上角的齿轮图标,然后添加“错误代码”列。您可以查看哪些日志条目失败。

也就是说,让我也谈谈为什么会出现该错误:“无论运行您的 aws cloudformation 的是什么”(cli、bash 脚本、github 操作、管道等上的 IAM 用户),都可能缺少 IAM 操作在 IAM 政策中。

例如,您可以尝试添加 elasticloadbalancing:* [到您的 IAM 用户的角色/策略] 只是为了检查您的 IAM 策略中是否缺少某些内容。然后您可以将范围缩小到:

  • elasticloadbalancing:创建监听器
  • elasticloadbalancing:创建LoadBalancerListeners
  • elasticloadbalancing:描述监听器
  • elasticloadbalancing:修改监听器
© www.soinside.com 2019 - 2024. All rights reserved.