Fn::GetAZs + Fn::Select 不合作
Fn::GetAZs + Fn::Select not co-operating
所以我的网络模板中有这个 CloudFormation 资源:
Resources:
...
PubSubnetAz2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: !FindInMap [VpcCidrs, !Ref "AWS::Region", pubsubnet2]
AvailabilityZone: !Select
- 1
- Fn::GetAZs: !Ref "AWS::Region"
我在尝试创建此堆栈时遇到此错误:
17:40:06 UTC-0700 CREATE_FAILED AWS::EC2::Subnet PubSubnetAz2 Template error: Fn::Select cannot select nonexistent value at index 1
模板验证,我有一个相同并通过的 PubSubnetAz1
块,(尽管它选择 index=0
)。
我使用Fn::GetAZs
错了吗?
PS。我正在使用 us-west-2
区域,据我所知有 > 1 个可用区。
Fn::GetAZs
文档显示了如下示例:
mySubnet:
Type: "AWS::EC2::Subnet"
Properties:
VpcId:
!Ref VPC
CidrBlock: 10.0.0.0/24
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ""
它有一个空区域,显然等同于指定 AWS::Region
。
它还显示了一个使用完整格式的示例:
"Fn::GetAZs": ""
"Fn::GetAZs": { Ref: "AWS::Region" }
"Fn::GetAZs": "us-east-1"
尝试其中一些格式,看看它们是否有效。
以下模板在 us-west-2
中成功部署了跨多个子网的 VPC:
---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
vpc1:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
InstanceTenancy: default
EnableDnsSupport: true
EnableDnsHostnames: false
Tags:
- Key: Name
Value: My-VPC
subnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ''
CidrBlock: 10.0.0.0/24
VpcId:
Ref: vpc1
Tags:
- Key: Name
Value: Subnet-A
subnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs: ''
CidrBlock: 10.0.1.0/24
VpcId:
Ref: vpc1
Tags:
- Key: Name
Value: Subnet-B
我手动创建了 VPC,使用 Hava to convert it to a JSON CloudFormation template, manually inserted the Select
statements, then converted to YAML using json2yaml.com。
我在第二次执行 AWS Mysfits 示例演示时遇到了类似的错误。我发现我需要列出我希望使用的可用区和成功创建的堆栈。
PrivateSubnetTwo:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-2b
VpcId: !Ref 'VPC'
CidrBlock: !FindInMap ['SubnetConfig', 'PrivateTwo', 'CIDR']
所以我的网络模板中有这个 CloudFormation 资源:
Resources:
...
PubSubnetAz2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: !FindInMap [VpcCidrs, !Ref "AWS::Region", pubsubnet2]
AvailabilityZone: !Select
- 1
- Fn::GetAZs: !Ref "AWS::Region"
我在尝试创建此堆栈时遇到此错误:
17:40:06 UTC-0700 CREATE_FAILED AWS::EC2::Subnet PubSubnetAz2 Template error: Fn::Select cannot select nonexistent value at index 1
模板验证,我有一个相同并通过的 PubSubnetAz1
块,(尽管它选择 index=0
)。
我使用Fn::GetAZs
错了吗?
PS。我正在使用 us-west-2
区域,据我所知有 > 1 个可用区。
Fn::GetAZs
文档显示了如下示例:
mySubnet:
Type: "AWS::EC2::Subnet"
Properties:
VpcId:
!Ref VPC
CidrBlock: 10.0.0.0/24
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ""
它有一个空区域,显然等同于指定 AWS::Region
。
它还显示了一个使用完整格式的示例:
"Fn::GetAZs": ""
"Fn::GetAZs": { Ref: "AWS::Region" }
"Fn::GetAZs": "us-east-1"
尝试其中一些格式,看看它们是否有效。
以下模板在 us-west-2
中成功部署了跨多个子网的 VPC:
---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
vpc1:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
InstanceTenancy: default
EnableDnsSupport: true
EnableDnsHostnames: false
Tags:
- Key: Name
Value: My-VPC
subnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ''
CidrBlock: 10.0.0.0/24
VpcId:
Ref: vpc1
Tags:
- Key: Name
Value: Subnet-A
subnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs: ''
CidrBlock: 10.0.1.0/24
VpcId:
Ref: vpc1
Tags:
- Key: Name
Value: Subnet-B
我手动创建了 VPC,使用 Hava to convert it to a JSON CloudFormation template, manually inserted the Select
statements, then converted to YAML using json2yaml.com。
我在第二次执行 AWS Mysfits 示例演示时遇到了类似的错误。我发现我需要列出我希望使用的可用区和成功创建的堆栈。
PrivateSubnetTwo:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-2b
VpcId: !Ref 'VPC'
CidrBlock: !FindInMap ['SubnetConfig', 'PrivateTwo', 'CIDR']