【问题标题】:AWS CloudformationAWS 云形成
【发布时间】:2017-05-21 21:30:30
【问题描述】:

嗯,我正在尝试在 AWS 中找到一个 cloudformation 模板。

我需要在哪里创建三个具有单个子网和实例的 VPC。您在其中有互联网网关,其中有 2 个从 vpc 到网关的单向连接和一个像这样的双向连接:

【问题讨论】:

  • 我猜你不会找到适合这种精确拓扑的样板 Cloudformation,但是你可以轻松地自己创建它。对于单向连接,您将需要使用 NAT 网关,对于双向连接,只需将 VPC 路由直接连接到 Internet 网关(或使用 ELB 或反向代理,具体取决于您要采取的安全措施.)
  • 如果您已经部署了如图所示的环境,您可以使用CloudFormer为您创建一个模板。 docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…另外,如果要传递自定义参数,可以修改CloudFormer生成的模板并声明参数docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…

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


【解决方案1】:

您可以利用 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

【讨论】:

    【解决方案2】:

    您可以使用 AWS 提供的现成模板并根据要求修改它们我正在分享链接供您参考。

    注意:Cloudformation 是基于 Json 的语法处理

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

    【讨论】:

      【解决方案3】:

      有一个很棒的工具,称为 AWS 控制台记录器,它是 Chrome 或 Firefox 的浏览器插件。它复制您在 AWS 控制台上执行的操作,并将它们转换为 CF、Terraform、Js 调用(因为 aws 中的所有内容都是 API)。 我建议构建小块,因为它非常处于测试阶段。它不能完成所有繁重的工作,但它可以减轻将网络图转换为一组有序的可管理 IaC 脚本的痛苦。他们有一个Git 页面。

      【讨论】:

        猜你喜欢
        • 2020-04-14
        • 2019-07-02
        • 2020-07-22
        • 2012-12-16
        • 2021-08-24
        • 2020-04-19
        • 2020-04-01
        • 2017-04-27
        • 2020-01-02
        相关资源
        最近更新 更多