好吧,我正在尝试在AWS中找到一个云形态模板。
我需要在哪里创建三个包含单个子网和实例的VPC。你有网关的地方,从vpc到网关的单向2和这样的双向连接:
答案 0 :(得分:5)
您可以利用AWS Quick Start Amazon VPC Architecture template快速开始使用样板VPC架构。此AWS支持的模板创建一个VPC,其中包含每个指定可用区内的公共(双向)和专用(单向,仅出站Internet)子网(您提供2-4个可用区作为参数)。我建议从快速入门开始,然后在必要时进行自定义以更好地满足您的特定需求。
对于您的用例,您可以指定2个可用区,然后在每个AZ中使用SubnetA和SubnetB中的私有子网,以及SubnetC的其中一个AZ中的Public Subnet。
(注意:我建议针对为单个应用程序创建3个单独的VPC。不同的子网提供足够的网络隔离,创建3个单独的VPC重复许多不必要的额外Internet Getways等资源,有一个limit of 5 VPCs per region per AWS account。)
这是一个完整的工作示例,它将“快速启动”模板直接用作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
答案 1 :(得分:0)
您可以使用AWS提供的现成模板,并根据我的共享链接进行修改,以供您参考。
注意:Cloudformation是基于Json的语法
答案 2 :(得分:0)
如果您已经在图表中部署了这样的环境,则可以使用CloudFormer为您创建模板。
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cloudformer.html
此外,如果要传递自定义参数,可以修改CloudFormer生成的模板并声明参数
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
答案 3 :(得分:0)