简体   繁体   English

CloudFormation嵌套堆栈参数

[英]CloudFormation nested stack parameters

I'm trying to reuse old VPC and ELB templates in a Nested CloudFormation stack. 我正在尝试在嵌套CloudFormation堆栈中重用旧的VPC和ELB模板。

VPC template: VPC模板:

 {
   "AWSTemplateFormatVersion" : "2010-09-09",
   "Description" : "AppVPC",
   "Resources" : {
      "AppVPC" : {
         "Type" : "AWS::EC2::VPC",
         "Properties" : {
            "CidrBlock" : "10.100.0.0/16",
            "EnableDnsSupport" : "true",
            "EnableDnsHostnames" : "true",
            "InstanceTenancy" : "default",
            "Tags" : [ {"Key" : "Name", "Value" : "appvpc"} ]
         }
      },

      "Pub1" :{
        "Type" : "AWS::EC2::Subnet",
        "Properties" : {
          "VpcId" : { "Ref": "AppVPC" },
          "CidrBlock" : "10.100.64.0/26",
          "AvailabilityZone" : "us-east-1a",
          "Tags" : [ {"Key" : "Name", "Value" : "public-1"} ]
        }
      } ,

  "Outputs" : {
  "public1" : {
    "Description": "Public Subnets",
    "Value" : { "Ref" : "Pub1" }
  }
 }
}

ELB Template: ELB模板:

{
   "AWSTemplateFormatVersion" : "2010-09-09",
   "Description" : "ELB",
   "Resources" : {

     "ELB" : {

       "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
   "Properties": {
      "CrossZone" : "True",
      "HealthCheck" : {
        "Target" : "HTTP:80/",
          "HealthyThreshold" : "3",
          "UnhealthyThreshold" : "5",
          "Interval" : "30",
          "Timeout" : "5"
      },
      "LoadBalancerName" : "ELB-APP",

      "Listeners" : [ {
          "LoadBalancerPort" : "80",
          "InstancePort" : "80",
          "Protocol" : "HTTP"
        } ],

    "Subnets" : [ "Pub1" ],


      "Tags" : [ {"Key" : "Name", "Value" : "ELB-APP"} ]
    }
   }
  }
 }

And finally I nested the two templates in a nested Stack: 最后,我将两个模板嵌套在一个嵌套堆栈中:

{
   "AWSTemplateFormatVersion": "2010-09-09",
   "Resources": {

       "VPC": {
           "Type": "AWS::CloudFormation::Stack",
           "Properties": {
               "TemplateURL": "https://s3.amazonaws.com/cloudformation-stack-custom/vpc.json",
               "TimeoutInMinutes": "60"
           }
       },

       "ELB": {
           "Type": "AWS::CloudFormation::Stack",
           "Properties": {
               "TemplateURL": "https://s3.amazonaws.com/cloudformation-stack-custom/elb.json",
               "Parameters": {
                  "Pub1" : { "Fn::GetAtt" : [ "VPC", "Outputs.public1" ] },
               },
               "TimeoutInMinutes": "60"
           }
       }
   }
}

My problem is that the ELB template requires the SubnetId and I'm passing the parameter Pub1 but it doesn't seem to work. 我的问题是ELB模板需要SubnetId,并且我传递了参数Pub1,但它似乎不起作用。

What I'm doing wrong? 我做错了什么?

The ELB template is missing a Parameters section. ELB模板缺少“ Parameters部分。

{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "ELB",
  "Parameters": {
    "Pub1": {
      "Type": "AWS::EC2::Subnet::Id"
    }
  },
  "Resources" : {
    "ELB" : {
      "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
      "Properties": {
        "CrossZone" : "True",
        "HealthCheck" : {
          "Target" : "HTTP:80/",
          "HealthyThreshold" : "3",
          "UnhealthyThreshold" : "5",
          "Interval" : "30",
          "Timeout" : "5"
        },
        "LoadBalancerName" : "ELB-APP",
        "Listeners" : [{
          "LoadBalancerPort" : "80",
          "InstancePort" : "80",
          "Protocol" : "HTTP"
        }],
        "Subnets" : [{"Ref": "Pub1"}],
        "Tags" : [{"Key": "Name", "Value": "ELB-APP"}]
      }
    }
  }
}

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

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