您可以利用 AWS Quick Start 的 Amazon VPC Architecture template 快速开始使用样板 VPC 架构。此 AWS 支持的模板在每个指定的可用区(您提供 2-4 个可用区作为参数)内创建一个包含公共(2 路)和私有(1 路,仅限出站 Internet)子网的单个 VPC。我建议从快速入门开始,然后在必要时进行自定义以更好地满足您的特定需求。
对于您的用例,您可以指定 2 个可用区,然后为 SubnetA 和 SubnetB 使用每个 AZ 中的私有子网,为 SubnetC 使用其中一个 AZ 中的公共子网。
(注意:我建议反对为单个应用程序创建 3 个单独的 VPC。不同的子网提供足够的网络隔离,创建 3 个单独的 VPC 会复制许多不必要的额外Internet Getways等资源,还有limit of 5 VPCs per region per AWS account。)
这是一个完整的工作示例,它直接将 Quick Start 模板用作 nested stack:
Description: Create a VPC with 2 private and 1 public subnets, with an EC2 instance in each.
Mappings:
RegionMap:
us-east-1:
# amzn-ami-hvm-2016.09.1.20161221-x86_64-gp2
"opal": "ami-9be6f38c"
"rstudio": "ami-9be6f38c"
Parameters:
InstanceType:
Description: EC2 instance type
Type: String
Default: t2.medium
AllowedValues: [t2.nano, t2.micro, t2.small, t2.medium, t2.large, t2.xlarge, t2.2xlarge,
m4.large, m4.xlarge, m4.2xlarge, m4.4xlarge, m4.10xlarge, m4.16xlarge,
c4.large, c4.xlarge, c4.2xlarge, c4.4xlarge, c4.8xlarge,
r4.large, r4.xlarge, r4.2xlarge, r4.4xlarge, r4.8xlarge, r4.16xlarge]
ConstraintDescription: Please choose a valid instance type.
AvailabilityZones:
Description: List of 2 Availability Zones to use for the subnets in the VPC.
Type: "List<AWS::EC2::AvailabilityZone::Name>"
KeyPairName:
Description: Public/private key pair to provide SSH access to the EC2 instances.
Type: "AWS::EC2::KeyPair::KeyName"
Resources:
VPCStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: 'https://s3.amazonaws.com/quickstart-reference/aws/vpc/latest/templates/aws-vpc.template'
Parameters:
AvailabilityZones: !Join [',', !Ref AvailabilityZones]
KeyPairName: !Ref KeyPairName
NumberOfAZs: 2
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: VPC Security Group
VpcId: !GetAtt VPCStack.Outputs.VPCID
OpalServer1:
Type: AWS::EC2::Instance
Properties:
ImageId: !FindInMap [ RegionMap, !Ref "AWS::Region", opal]
InstanceType: !Ref InstanceType
SecurityGroupIds: [!Ref SecurityGroup]
SubnetId: !GetAtt VPCStack.Outputs.PrivateSubnet1AID
KeyName: !Ref KeyPairName
OpalServer2:
Type: AWS::EC2::Instance
Properties:
ImageId: !FindInMap [ RegionMap, !Ref "AWS::Region", opal]
InstanceType: !Ref InstanceType
SecurityGroupIds: [!Ref SecurityGroup]
SubnetId: !GetAtt VPCStack.Outputs.PrivateSubnet2AID
KeyName: !Ref KeyPairName
RStudioClient:
Type: AWS::EC2::Instance
Properties:
ImageId: !FindInMap [ RegionMap, !Ref "AWS::Region", rstudio]
InstanceType: !Ref InstanceType
SecurityGroupIds: [!Ref SecurityGroup]
SubnetId: !GetAtt VPCStack.Outputs.PublicSubnet1ID
KeyName: !Ref KeyPairName