Amazon web services 属性参数的值必须是具有字符串(或简单类型)属性的对象

Amazon web services 属性参数的值必须是具有字符串(或简单类型)属性的对象,amazon-web-services,amazon-ec2,yaml,Amazon Web Services,Amazon Ec2,Yaml,我试图通过填充来自另一个嵌套堆栈输出的值,将参数传递给其中一个嵌套堆栈 我不希望任何交叉引用(除非没有办法) 这个想法很直截了当 RootStack -NstdStackVPC -NstdStackSG -NstdStackEC2 问题出在创建EC2时的最后一个嵌套堆栈上。 如果我直接在根堆栈中创建了资源,那么将创建EC2 Description: RootStack Parameters: MyKeyName: Type: AWS::EC2::KeyPair::KeyName D

我试图通过填充来自另一个嵌套堆栈输出的值,将参数传递给其中一个嵌套堆栈

我不希望任何交叉引用(除非没有办法)

这个想法很直截了当

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,我自己也最终解决了这个问题

在我的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
现在在根堆栈中

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    
在我的巢穴里

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


希望这有帮助。(如果不是在解决问题时,那么至少是在指向正确的方向时)

我遇到了同样的错误消息,其中有一个类似的问题和解决方案。我来到这里,由于问题略有不同,这个问题帮助我找到了解决方案。所以,我不想劫持这个问题,只是希望为下一位来访者提供我发现的额外有用的东西

我嵌套了一个集群模板,非常类似于和OPs示例。以字符串列表的形式传递子网(如果您想了解更多信息,请参阅列表)

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]