AWS Cloudformation

时间:2017-01-07 02:34:35

标签: amazon-web-services amazon-vpc amazon-cloudformation infrastructure

好吧,我正在尝试在AWS中找到一个云形态模板。

我需要在哪里创建三个包含单个子网和实例的VPC。你有网关的地方,从vpc到网关的单向2和这样的双向连接:

enter image description here

4 个答案:

答案 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

Launch 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的语法

链接: - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/sample-templates-services-us-west-2.html#d0e207425

答案 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)

有一个很棒的工具叫做AWS Console Recorder,它是ChromeFirefox的浏览器插件。它将复制您在AWS控制台上执行的操作,并将其转换为CF,Terraform,Js调用(因为aws中的所有内容都是API)。     我建议您构建小块,因为它是Beta版。它无法完成所有繁重的工作,但可以减轻将网络图转换为一组有序可管理IaC脚本的麻烦。他们有一个Git页面。