gpt4 book ai didi

amazon-web-services - AWS 中的参数引用

转载 作者:行者123 更新时间:2023-12-03 07:36:20 25 4
gpt4 key购买 nike

在下面的代码中,我尝试引用我为为 EC2 实例创建subnets\cidr block 而创建的参数。

我猜,因为我将 CFCidrVPC1 创建为字符串,而实际的 IP 地址不是字符串。

我在这里缺少一些东西。

有人可以在这里指导我吗?我尝试这样做的原因是将来重用这些代码。我还尝试在 Fn::Cidr 函数中使用 Ref 函数,但这也不起作用。所以用 cidr block 替换它。

我收到的错误是“属性 SubnetId 的值必须是字符串类型”

请找到我的完整脚本:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Creating template to deploy 3 ec2 instances in 3 different AZs",
"Parameters": {
"CFCidrVPC1": {
"Type": "String",
"Default": "10.10.0.0/16"
},
"CFCidrVPC2": {
"Type": "String",
"Default": "10.20.0.0/16"
},
"CFEC2Instancetype": {
"Type": "String",
"Default": "t2.micro",
"Description": " Only t2.micro is available in the free tier account hence no any other options"
}
},
"Resources": {
"VPC1": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": {
"Ref": "CFCidrVPC1"
},
"EnableDnsHostnames": "False",
"EnableDnsSupport": "False",
"InstanceTenancy": "default"
}
},
"VPC2": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": {
"Ref": "CFCidrVPC2"
},
"EnableDnsHostnames": "False",
"EnableDnsSupport": "False",
"InstanceTenancy": "default"
}
},
"CFsubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"0",
{
"Fn::Cidr": [
"10.10.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC1"
}
}
},
"CFsubnet2": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"1",
{
"Fn::Cidr": [
"10.10.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC1"
}
}
},
"CFsubnet3": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"0",
{
"Fn::Cidr": [
"10.20.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC2"
}
}
},
"CFsubnet4": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"1",
{
"Fn::Cidr": [
"10.10.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC2"
}
}
},
"FirstECSinVPC1AZ1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet1"
}
}
},
"FirstECSinVPC1AZ2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"1",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet2"
}
}
},
"FirstECSinVPC2AZ1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet3"
}
}
},
"FirstECSinVPC2AZ2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"1",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet4"
}
}
}
}
}

最佳答案

cloudformation 中的所有内容都区分大小写。

你有:

"SubnetId": {
"ref": "CFsubnet2"
}

尝试:

"SubnetId": {
"Ref": "CFsubnet2"
}

对于所有出现的情况。

关于amazon-web-services - AWS 中的参数引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56114217/

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