cfn-lint
这样做时,会抱怨硬编码可用性区域:
Resources:
SubnetWest2a:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-west-2a
CidrBlock: 10.0.0.0/24
VpcId: !Ref GlobalVPC
SubnetWest2b:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-west-2b
CidrBlock: 10.0.1.0/24
VpcId: !Ref GlobalVPC
SubnetWest2c:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-west-2c
CidrBlock: 10.0.2.0/24
VpcId: !Ref GlobalVPC
所以我就这样做了:
Resources:
#...
SubnetWest1:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.0.0/24
VpcId: !Ref GlobalVPC
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref 'AWS::Region'
SubnetWest2:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.1.0/24
VpcId: !Ref GlobalVPC
AvailabilityZone: !Select
- 1
- Fn::GetAZs: !Ref 'AWS::Region'
SubnetWest3:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.2.0/24
VpcId: !Ref GlobalVPC
AvailabilityZone: !Select
- 2
- Fn::GetAZs: !Ref 'AWS::Region'
但警告来自
Fn::GetAZs docs
:
与descripe availability zones AWS CLI命令的响应类似,Fn::GetAZs函数的结果顺序不受保证,并且在添加新的可用性区域时可能会发生变化。
依赖于这些子网和CIDR块的节是:
GlobalDBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Multi-AZ RDS subnet group
SubnetIds:
- !Ref SubnetWest1
- !Ref SubnetWest2
- !Ref SubnetWest3
考虑到这两者相互排斥
最佳实践提示
,有没有更好的发现方法
创造
这是一组相互依赖的资源,用于多个应用程序,并且每次运行堆栈时都会得到确定的结果?