【问题标题】:Passing Target Group Target as Parameters Cloud Formation将目标组目标作为参数传递 Cloud Formation
【发布时间】:2021-03-18 19:33:43
【问题描述】:

我正在尝试创建一个AWS::ElasticLoadBalancingV2::TargetGroup,它接受 Target 作为以下模板的参数:

FETargetGroup:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    Properties:
      Name: !Sub 'targetgroup-ccp-fe-${EnvironmentName}'
      Port: 443
      Protocol: HTTPS
      TargetType: ip
      Targets: 
        - Id: !Select[0,!Split [",", !Ref TargetGroupIPs]]
        - Id: !Select[1,!Split [",", !Ref TargetGroupIPs]]
      VpcId: !Ref VPC  

还有参数:

  TargetGroupIPs:
   Description: IPs to be included in Target Group
   Type: String 

这里的问题是 2 个 IP 是静态的,我希望它接受 x 个 IP。例如:

FETargetGroup:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    Properties:
      Name: !Sub 'targetgroup-ccp-fe-${EnvironmentName}'
      Port: 443
      Protocol: HTTPS
      TargetType: ip
      Targets: !Split [",", !Ref TargetGroupIPs]
      VpcId: !Ref VPC      

但我得到验证错误:目标接受对象列表。如何正确完成?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    如何正确完成?

    不能以普通方式完成 CloudFormation (CFN)。这需要一个循环机制,而 CFN 中不存在。

    要克服这个问题,您必须创建 CFN macrocustom resource。在这两种情况下,您都必须编写一个 lambda 函数。不同之处在于宏的函数将解析您的原始模板(或它的片段)并动态构造Targets。相比之下,自定义资源的函数将使用 AWS SDK 将您的 TargetGroupIPs 作为其输入参数来完全创建目标组。

    【讨论】:

      猜你喜欢
      • 2018-04-18
      • 1970-01-01
      • 2021-04-08
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 2019-09-11
      相关资源
      最近更新 更多