【问题标题】:Value of property Parameters must be an object with String (or simple type) properties属性参数的值必须是具有字符串(或简单类型)属性的对象
【发布时间】:2020-03-27 08:09:39
【问题描述】:

我正在尝试通过填充另一个嵌套堆栈输出中的值来将参数传递给其中一个嵌套堆栈。

而且我不想要任何交叉引用(除非没有办法绕过它)

这个想法非常简单。

RootStack

-NstdStackVPC
-NstdStackSG
-NstdStackEC2

问题出在创建 EC2 时的最后一个嵌套堆栈上。 如果我直接在根堆栈中创建资源,则会创建 EC2

Description: RootStack
Parameters:
 MyKeyName:
  Type: AWS::EC2::KeyPair::KeyName
  Default: my-test-key
 EC2ImageId:
  Type: AWS::EC2::Image::Id
  Default: ami-0dxxxxa

Resources:
 NstdStackVPC ......
 NstdStackSG ......

 EC2Host: 
  Type: AWS::EC2::Instance
  Properties:
   SubnetId: !GetAtt NstdStackVPC.Outputs.VPCPubSubnet
   ImageId: !Ref EC2ImageId
   InstanceType: t2.micro
   KeyName: !Ref MyKeyName
   SecurityGroupIds: 
   - !GetAtt NstdStackSG.Outputs.SecGrp4EC2Host

但如果我尝试将 EC2 创建为嵌套堆栈

AWSTemplateFormatVersion: '2010-09-09'
Description: NstdStackEC2.
Parameters:
 myNstdKeyName:
  Type: AWS::EC2::KeyPair::KeyName
 myNstdImageId:
  Type: AWS::EC2::Image::Id
 myNstdSecGrp:
  Type: AWS::EC2::SecurityGroup::Id
 myNstdEC2HostSubnet:
  Type: AWS::EC2::Subnet::Id

Resources:
 EC2Host: 
  Type: AWS::EC2::Instance
  Properties:
   SubnetId: !Ref myNstdEC2HostSubnet
   ImageId: !Ref myNstdImageId
   InstanceType: t2.micro
   KeyName: !Ref myNstdKeyName
   SecurityGroupIds:
    - Ref myNstdSecGrp  

如下改变根栈

AWSTemplateFormatVersion: '2010-09-09'
Description: RootStack
Parameters:
 MyKeyName:
  Type: AWS::EC2::KeyPair::KeyName
  Default: my-test-key
 EC2ImageId:
  Type: AWS::EC2::Image::Id
  Default: ami-0dxxxxa

Resources:
 NstdStackVPC ......
 NstdStackSG ......
 NstdStackEC2:
  Type: AWS::CloudFormation::Stack
  Properties:
   TemplateURL: https://bkt.s3.eu-central-1.amazonaws.com/NstdEC2Host.yml
   Parameters:
    myNstdKeyName: !Ref MyKeyName
    myNstdImageId: !Ref EC2ImageId
    myNstdSecGrp: !GetAtt NstdStackSG.Outputs.SecGrp4BasHost
    myNstdEC2HostSubnet: !GetAtt NstdStackVPC.Outputs.VPCPubSubnet   

它给了我以下错误: 属性参数的值必须是具有字符串(或简单类型)属性的对象

试过去掉所有参数来一一尝试。但它在所有事情上都失败了。 即使是直接从根堆栈引用的参数,即 MyKeyName、EC2ImageId

【问题讨论】:

    标签: amazon-web-services amazon-ec2 yaml


    【解决方案1】:

    我遇到了相同的错误消息,并带有类似的问题和解决方案。我来到这里,由于问题略有不同,这个问题帮助我找到了解决方案。所以,不要试图劫持这个问题,只是希望为下一个访问者提供我发现的其他有用的信息。

    我正在嵌套一个与this one 和 OP 示例非常相似的集群模板。将子网作为字符串列表传递(我相信 List<:some::type> 也可以)。

    Subnets:
      Description: Subnets of the of the cluster availaibility zone
      Type: CommaDelimitedList
      Default: subnet-0d..de,subnet-0e..7a,subnet-0b..24
    

    而我使用上面的参数来调用部分子模板如下。

    ECS:
      Type: AWS::CloudFormation::Stack
      Properties:
        TemplateURL: https://xx.amazonaws.com/yy/zz.yaml
        Parameters:
          SecurityGroups: !Join [",", [!GetAtt SecurityGroups.Outputs.ECSHostSecurityGroup]]
          Subnets: !Join [",", !Ref Subnets]
    

    因此,在上面的示例中,SecurityGroup 被连接在一起成为来自 SecurityGroup 嵌套模板的输出的列表,但子网只是通过逗号分隔的参数连接在一起。有一个knowledge-center article too,如果你想了解更多信息。 TA OP

    【讨论】:

    • 我遇到了一个非常相似的问题,但是我从 SSM 参数中输入了逗号分隔的字符串列表 (StringList)。我只是想不通为什么当我将 SSM StringList 值(读作 CommaDelimitedList CFT 根堆栈参数)传递给嵌套堆栈时无法接受它,它也需要一个 CommaDelimitedList 参数。您使用 !Join 的解决方案非常有效,谢谢!
    【解决方案2】:

    好的,终于自己解决了。

    在我的 NstdStackSG 输出部分中,我指的是对象本身。 这就是问题所在。

    AWSTemplateFormatVersion: 2010-09-09
    Description: Security group nested stack
    Resources:
     MySecGrp
      Type: ....
      .....
      ....
    Outputs:
     MyOtptSecGrp:
    #This one is working for me.
      Value: !GetAtt MySecGrp.GroupId
    #previously i was assigning the following value
      #Value: !Re MySecGrp
    

    现在在 RootStack 中

    AWSTemplateFormatVersion: '2010-09-09'
    Description: RootStack
    Parameters:
     MyKeyName:
      Type: AWS::EC2::KeyPair::KeyName
      Default: my-test-key
     EC2ImageId:
      Type: AWS::EC2::Image::Id
      Default: ami-0dxxxxa
    Resources:
     NstdStackVPC ......
     NstdStackSG ......
     NstdStackEC2:
      Type: AWS::CloudFormation::Stack
      Properties:
       TemplateURL: https://bkt.s3.eu-central-1.amazonaws.com/NstdEC2Host.yml
       Parameters:
        myNstdKeyName: !Ref MyKeyName
        myNstdImageId: !Ref EC2ImageId
        myNstdSecGrp: !GetAtt NstdStackSG.Outputs.SecGrp4BasHost
        myNstdEC2HostSubnet: !GetAtt NstdStackVPC.Outputs.VPCPubSubnet    
    

    在我的嵌套EC2Stack中

    AWSTemplateFormatVersion: 2010-09-09
    Description: NstdStackEC2
    
    Parameters:
     myNstdSecGrp:
      Type: AWS::EC2::SecurityGroup::Id
     myNstdEC2HostSubnet:
      Type: AWS::EC2::Subnet::Id
     myNstdKeyName:
      Type: AWS::EC2::KeyPair::KeyName
     myNstdImageId:
      Type: AWS::EC2::Image::Id
    
    Resources:
    
     EC2Host: 
      Type: AWS::EC2::Instance
      Properties:
       SubnetId: !Ref myNstdEC2HostSubnet
       ImageId: !Ref myNstdImageId
       InstanceType: t2.micro
       KeyName: !Ref myNstdKeyName
       SecurityGroupIds:
        - !Ref myNstdSecGrp
    
    

    希望这会有所帮助。 (如果没有解决,那么至少要指出正确的方向)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-09
      • 2019-10-24
      • 2016-01-23
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      相关资源
      最近更新 更多