简体   繁体   English

AWS 云形成

[英]AWS Cloudformation

Well, I am trying to find a cloudformation template in AWS.好吧,我正在尝试在 AWS 中找到一个 cloudformation 模板。

Where would I need to create three VPC's with single subnet and instance in it.我需要在哪里创建三个具有单个子网和实例的 VPC。 Where you have internetgateway in it with 2 one-way from vpc to gateway and one two-way connection like this:如果你有互联网网关,它有 2 个从 vpc 到网关的单向连接和一个像这样的双向连接:

在此处输入图片说明

You can leverage the AWS Quick Start 's Amazon VPC Architecture template to get started quickly with a boilerplate VPC architecture.您可以利用AWS Quick StartAmazon VPC 架构模板快速开始使用样板 VPC 架构。 This AWS-supported template creates a single VPC containing both a public (2-way) and private (1-way, outbound Internet only) subnet within each specified Availability Zone (you provide 2-4 Availability Zones as Parameters).此 AWS 支持的模板在每个指定的可用区(您提供 2-4 个可用区作为参数)内创建一个包含公共(2 向)和私有(1 向,仅限出站 Internet)子网的单个 VPC。 I would recommend starting with the Quick Start, then later customizing to better fit your specific needs if necessary.我建议从快速入门开始,然后在必要时进行自定义以更好地满足您的特定需求。

For your use case, you could specify 2 Availability Zones, then use the Private Subnets in each AZ for SubnetA and SubnetB, and the Public Subnet in one of the AZs for SubnetC.对于您的用例,您可以指定 2 个可用区,然后将每个可用区中的私有子网用于 SubnetA 和 SubnetB,并在其中一个可用区中为 SubnetC 使用公共子网。

( Note: I recommend against creating 3 separate VPCs for a single application. Distinct Subnets provide adequate network isolation, creating 3 separate VPCs duplicates many unnecessary additional resources such as Internet Getways, and there is a limit of 5 VPCs per region per AWS account .) 注意:我建议不要为单个应用程序创建 3 个单独的 VPC。不同的子网提供足够的网络隔离,创建 3 个单独的 VPC 会复制许多不必要的额外资源,例如 Internet Getways,并且每个 AWS 账户每个区域限制 5 个 VPC 。 )

Here's a full working example that uses the Quick Start template directly as a 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

You can use readymade templates provided by AWS and modify them as per requirement I am sharing link for your reference.您可以使用 AWS 提供的现成模板并根据需要修改它们,我正在共享链接供您参考。

Note : Cloudformation is Json based take care of syntax注意:Cloudformation 是基于 Json 的注意语法

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

If you have already deployed such environment as in diagram, you can use CloudFormer to create a template for you. 如果您已经部署了如图所示的环境,则可以使用CloudFormer为您创建模板。

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cloudformer.html http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cloudformer.html

Furthermore, if you want to pass custom parameters, you can modify the template generated by CloudFormer and declare parameters 此外,如果要传递自定义参数,则可以修改CloudFormer生成的模板并声明参数

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html

There is an awesome tool called Console Recorder for AWS, it's a browser plugin for Chrome or Firefox .有一个很棒的工具叫做 Console Recorder for AWS,它是ChromeFirefox的浏览器插件。 It copies the actions you perform on the AWS console and converts them into CF, Terraform, Js calls ( because everything in aws is an API ).它复制您在 AWS 控制台上执行的操作并将它们转换为 CF、Terraform、Js 调用(因为 aws 中的所有内容都是 API)。 I'd advise building small chunks as it's very beta.我建议构建小块,因为它是非常测试版的。 It can't do all the heavy lifting, but it can take the pain out of turning a Network diagram into a set of ordered managable IaC scripts.它不能完成所有繁重的工作,但它可以减轻将网络图转换为一组有序的可管理 IaC 脚本的痛苦。 They have a Git page.他们有一个Git页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM