简体   繁体   English

AWS Cloudformation主模板创建

[英]AWS Cloudformation Master Template creation

I am trying to create a master template which calls other templates.My first template is VPC and subnet creation and second one is creating bastion host. 我正在尝试创建一个调用其他模板的主模板。我的第一个模板是VPC和子网创建,第二个是创建堡垒主机。 Problem i am facing is i am not able to ref. 我面临的问题是我无法参考。 the created VPC in my second template due to which its failing. 由于第二个模板失败而在我的第二个模板中创建了VPC。 My master template looks like below:- 我的主模板如下所示:-

Description: >

    This template deploys the full agyle time stack as follows, which consists of:

    A VPC with with public and private subnets spread across two Availabilty Zones.
    It deploys an Internet Gateway and a pair of NAT Gateways, with the relevant routes in each of the subnets.

    It then deploys the API ECS cluster distributed across multiple Availability Zones.

    Finally, it deploys the API ECS services deployed as containers within the ECS repository
Parameters:
    S3TemplateKeyPrefix:
        Description: >
            An S3 key prefix which will be used to resolve referenced templates
        Type: String

Resources:

    VPC:
        Type: AWS::CloudFormation::Stack
        Properties:
            TemplateURL: !Sub ${S3TemplateKeyPrefix}/infrastructure/vpc.yaml

    Bastion:
        Type: AWS::CloudFormation::Stack
        Properties:
            TemplateURL: !Sub ${S3TemplateKeyPrefix}/infrastructure/bastion.yaml
            Parameters: 
                EnvironmentName: !Ref AWS::StackName
                VPC: !GetAtt VPC.Outputs.VPC

Can someone help me here do i have to modify VPC and Bastion host template to reference my VPC in bastion template. 有人可以帮我吗,我是否必须修改VPC和堡垒主机模板才能在堡垒模板中引用我的VPC。

Based on your master template, I believe it fails because CFN starts creating both of them in parallel, whereas Bastion needs to be created after your VPC resource. 根据您的主模板,我相信它会失败,因为CFN会开始同时并行创建它们,而Bastion需要在您的VPC资源之后创建。 Just add the DependsOn: VPC for your Bastion resource to have it created only after your VPC has been created. 只需为您的Bastion资源添加DependsOn: VPC ,即可在创建VPC之后创建它。

Bastion:
  Type: AWS::CloudFormation::Stack
  DependsOn: VPCStack
  Properties:

Here's a working example from AWS saas-identity-cognito-master.template . 这是AWS saas-identity-cognito-master.template中的一个工作示例。

I was able to resolve the issue with modifying the child templates with Export and Import Function and calling it in master template. 我可以通过使用“导出和导入功能”修改子模板并在主模板中调用子模板来解决该问题。 below is what I used:- 以下是我使用的:

Outputs: 输出:

PubPrivateVPC: 
    Description: A reference to the created VPC
    Value: !Ref PubPrivateVPC
    Export:
      Name: VPC-PROD

and import 并导入

Parameter:- NetworkStackName: Description: >- Name of an active CloudFormation stack that contains the networking resources, such as the subnet and security group, that will be used in this stack. 参数:-NetworkStackName:描述:>-活动CloudFormation堆栈的名称,该堆栈包含将在此堆栈中使用的网络资源,例如子网和安全组。 Type: String MinLength: 1 MaxLength: 255 AllowedPattern: '^[a-zA-Z][-a-zA-Z0-9]*$' Default: VPC-PROD 类型:字符串最小长度:1最大长度:255允许模式:'^ [a-zA-Z] [-a-zA-Z0-9] * $'默认值:VPC-PROD

and in resources called like below:- VpcId: !ImportValue VPC-PROD 并在如下所示的资源中调用:-VpcId:!ImportValue VPC-PROD

No i am able to call child templates in master successfully. 不,我能够成功调用母版中的子模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM