所以我在我的网络模板中有这个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个AZs.
最佳答案 以下模板在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将其转换为JSON CloudFormation模板,手动插入Select语句,然后使用json2yaml.com转换为YAML.