1

Ich versuche, alte VPC- und ELB-Vorlagen in einem geschachtelten CloudFormation-Stapel wiederzuverwenden.CloudFormation verschachtelte Stapelparameter

VPC-Vorlage:

{ 
    "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 Vorlage:

{ 
    "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"} ] 
    } 
    } 
    } 
} 

Und schließlich verschachtelt ich die beiden Vorlagen in einem verschachtelten 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" 
      } 
     } 
    } 
} 

Mein Problem ist, dass die ELB-Vorlage benötigt die SubnetId und ich übergebe den Parameter Pub1, aber es scheint nicht zu funktionieren.

Was mache ich falsch?

Antwort

3

In der ELB-Vorlage fehlt ein Abschnitt 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"}] 
     } 
    } 
    } 
} 
+0

ja, das war das Problem. – Libert

Verwandte Themen