【问题标题】:Value of property Id must be of type String - Error in CloudFormation template属性 ID 的值必须是字符串类型 - CloudFormation 模板中的错误
【发布时间】:2021-11-23 09:46:49
【问题描述】:

我正在使用以下 cloudformation 模板为 NLB 创建目标组。在执行 cloudformation 模板时,由于 Targets: - Id: !Ref InstanceID 行,我收到错误“属性 Id 的值必须是字符串类型”。我选择了 AWS::EC2::Instance::Id 作为列表,因为想要关联此目标组中的多个实例。请任何人帮助我了解确切的问题在哪里。

Parameters:
  InstanceID:
    Description: Please Select the Instance IDs
    Type: List<AWS::EC2::Instance::Id>
    Description: Select Instance ID to associate it with the Target Group
  VPC:
    Description: The VPC to deploy to the target group
    Type: AWS::EC2::VPC::Id
    ConstraintDescription: Select VPC ID for the Target Group

Resources:
    EC2TargetGroup:
      Type: AWS::ElasticLoadBalancingV2::TargetGroup
      Properties:                                                     
        HealthCheckIntervalSeconds: 30
        HealthCheckProtocol: TCP
        HealthCheckTimeoutSeconds: 10
        HealthyThresholdCount: 3        
        Name: NLBTargetGroupForEndpointService
        Port: 22
        Protocol: TCP        
        TargetType: instance
        Targets:
         - Id: !Ref InstanceID
        UnhealthyThresholdCount: 3
        VpcId: !Ref VPC
        Tags:
        - Key: Name
          Value: EC2TargetGroup
        - Key: Port
          Value: 22
        - Key: Protocol
          Value: TCP

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-elb


    【解决方案1】:

    您不能这样做,因为 Targets 是一个对象 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-targetgroup-targetdescription.html

    如果您想要动态填充目标,您必须开发自己的 cloudformation 宏或自定义资源。

    【讨论】:

    • 它抛出错误“属性目标的值必须是对象列表”,更改为“目标:!Ref InstanceID”。
    【解决方案2】:

    看着!Ref InstanceID,我认为它得到了多值字符串而不是一个InstanceId。您可以尝试将 InstanceId 参数设置为 String 类型。

    请参阅 https://aws.amazon.com/premiumsupport/knowledge-center/multiple-values-list-parameter-cli/,其中解释了安全组参考。

    【讨论】:

      猜你喜欢
      • 2020-03-25
      • 1970-01-01
      • 2020-07-14
      • 2021-12-05
      • 1970-01-01
      • 2020-11-06
      • 2019-04-22
      • 1970-01-01
      • 2017-04-16
      相关资源
      最近更新 更多