gpt4 book ai didi

json - CloudFormation 嵌套堆栈参数

转载 作者:行者123 更新时间:2023-12-01 16:02:26 25 4
gpt4 key购买 nike

我正在尝试在嵌套 CloudFormation 堆栈中重用旧的 VPC 和 ELB 模板。

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 模板:

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

最后我将这两个模板嵌套在一个嵌套的 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"
}
}
}
}

我的问题是 ELB 模板需要 SubnetId,并且我传递了参数 Pub1,但它似乎不起作用。

我做错了什么?

最佳答案

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

关于json - CloudFormation 嵌套堆栈参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39312567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com