Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何在嵌套堆栈中使用AWS CloudFormation模板中的映射 我们考虑下面的映射< /代码>和 FindInMap 用于同一个AWS云计算模板中。他们会成功的 现在,考虑 VPCIDs/COD> 映射> > YAML< /COD>模板,我试图从嵌套.yAML模板中使用< 映射> >代码> 模板。_Amazon Web Services_Mapping_Amazon Cloudformation_Nested Stack - Fatal编程技术网

Amazon web services 如何在嵌套堆栈中使用AWS CloudFormation模板中的映射 我们考虑下面的映射< /代码>和 FindInMap 用于同一个AWS云计算模板中。他们会成功的 现在,考虑 VPCIDs/COD> 映射> > YAML< /COD>模板,我试图从嵌套.yAML模板中使用< 映射> >代码> 模板。

Amazon web services 如何在嵌套堆栈中使用AWS CloudFormation模板中的映射 我们考虑下面的映射< /代码>和 FindInMap 用于同一个AWS云计算模板中。他们会成功的 现在,考虑 VPCIDs/COD> 映射> > YAML< /COD>模板,我试图从嵌套.yAML模板中使用< 映射> >代码> 模板。,amazon-web-services,mapping,amazon-cloudformation,nested-stack,Amazon Web Services,Mapping,Amazon Cloudformation,Nested Stack,我怎样才能做到这一点 # master.yaml Mappings: VpcIds: us-east-1: "123456789012": "vpc-00011122233344455" "234567890123": "vpc-11122233344455566" us-west-1: "123456789012": "vpc

我怎样才能做到这一点

# master.yaml
Mappings:
  VpcIds:
    us-east-1: 
      "123456789012": "vpc-00011122233344455"
      "234567890123": "vpc-11122233344455566"
    us-west-1: 
      "123456789012": "vpc-22233344455566677"
      "234567890123": "vpc-33344455566677788"


# nested.yaml
Resources:
  EgressOnlyInternetGateway:
    Type: AWS::EC2::EgressOnlyInternetGateway
    Properties:
      VpcId: !FindInMap [VpcIds, !Ref "AWS::Region", !Ref "AWS::AccountId"]
更新:我试图使用
MyTestMasterStack
中定义的映射参数在
MyTestNestedStack
MyTestNestedStack.yaml
)中创建一个资源
MyTestNestedSg
,如下所示。我收到错误:
针对
MyTestNestedStack
为不需要参数值的模板指定的参数值

我如何解决这个问题

请注意,
MyTestMasterStack
下的资源
MyTestMasterSg
只是为了完整性

# MyTestMasterStack.yaml
Mappings:
  VpcIds:
    us-east-1: 
      "123456789012": "vpc-00011122233344455" 
      "234567890123": "vpc-11122233344455566" 

Resources:
  MyTestNestedStack:
    Type: AWS::CloudFormation::Stack
    Properties: 
      Parameters: 
        VpcId: !FindInMap [VpcIds, !Ref "AWS::Region", !Ref "AWS::AccountId"]
      TemplateURL: "https://s3.amazonaws.com/my_template_bucket_name/MyTestNestedStack.yaml"
      TimeoutInMinutes: 60

  MyTestMasterSg:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: "vpc-017a12485ad93e94a"
      GroupDescription: Testing resource creation wtih Mappings from the parent Stack
      GroupName: MyTestMasterSg
      SecurityGroupIngress:
        - CidrIp: 10.1.0.0/16
          FromPort: 80
          IpProtocol: tcp
          ToPort: 80

# MyTestNestedStack.yaml
Resources:
  MyTestNestedSg:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref VpcId
      GroupDescription: Testing resource creation wtih Mappings from the parent Stack
      GroupName: MyTestNestedSg
      SecurityGroupIngress:
        - CidrIp: 10.1.0.0/16
          FromPort: 8080
          IpProtocol: tcp
          ToPort: 8080

你不能这样做。您必须将解析的映射值传递到
AWS::CloudFormation::Stack
资源

嵌套堆栈应该是自给自足的,并且它们无权访问父堆栈的参数、映射或资源。它们只能处理您显式通过
AWS::CloudFormation::Stack
资源的
参数
传递的数据

因此,在父级堆栈中,您必须执行以下操作:

MyNestedStack:
  Type: AWS::CloudFormation::Stack
  Properties: 
    Parameters: 
      VpcId : !FindInMap [VpcIds, !Ref "AWS::Region", !Ref "AWS::AccountId"]
  TemplateURL: String
更新

您的
MyTestNestedStack.yaml
缺少
参数

Parameters:
  
  VpcId:
    Type: AWS::EC2::VPC::Id


感谢@Marcin的及时回复。我遵循了这一点。然后我在
MyNestedStack
模板中,使用了这个引用
VpcId:!请参考VpcId
,以创建安全组,但该操作失败,为不需要它们的模板指定了错误
参数值。
针对
MyNestedStack
。不确定我是否遗漏了其他内容。@Rafiq您能用模板的当前状态更新您的问题吗?谢谢@Marcin。请查看更新。@Rafiq I更新了答案。请看一看。