繁体   English   中英

如何在不使用 AutoScaling 的情况下使用 aws cloudformation 启动多个 EC2 实例?

[英]How can I launch more than one EC2 instances using aws cloudformation without using AutoScaling?

我想在不使用 AutoScaling 的情况下使用 aws cloudformation 模板启动多个 Ec2 实例。 请让我知道如何启动?

在没有 Autoscaling Group 的情况下,有多种方法可以使用 CloudFormation 启动多个实例。

  1. 在同一 Cloudformation 模板中创建所需数量的资源。 例如。 如果要启动 3 个实例,则必须编写代码以在 Cloudformation 模板中启动 3 个 AWS 实例。

以下模板有 2 个资源,将启动 2 个 EC2 实例。 您可以根据需要添加更多资源。

server1:
Type: AWS::EC2::Instance
Properties:
  InstanceType: !Ref Server1InstanceType
  KeyName: !Ref ServerKeypair
  ImageId: !Ref ServerImageId
  SecurityGroupIds: 
    - !Ref ServerSG
  SubnetId: !Ref PrivateWeb1b
  Tags:
  - Key: Name
    Value: server1

server2:
Type: AWS::EC2::Instance
Properties:
  InstanceType: !Ref Server2InstanceType
  KeyName: !Ref ServerKeypair
  ImageId: !Ref ServerImageId
  SecurityGroupIds: 
    - !Ref ServerSG
  SubnetId: !Ref PrivateWeb1b
  Tags:
  - Key: Name
    Value: server2
  1. 使用相同的 Cloudformation 模板创建多个 Cloudformation 堆栈。 例如。 您必须从相同的 Cloudformation 模板创建 2 个 Cloudformation 堆栈,该模板具有每个启动 1 个 EC2 实例的资源。

以下模板有 1 个资源,将启动 1 个 EC2 实例。 按照第二种方法,您可以使用相同的模板创建多个 Cloudformation 堆栈以获取多个 EC2 实例。

server1:
Type: AWS::EC2::Instance
Properties:
  InstanceType: !Ref Server1InstanceType
  KeyName: !Ref ServerKeypair
  ImageId: !Ref WebserverImageId
  SecurityGroupIds: 
    - !Ref WebserverSG
  SubnetId: !Ref PrivateWeb1b
  Tags:
  - Key: Name
    Value: server1

尝试使用类型: AWS::EC2::EC2Fleet

您可以指定配置信息以启动一组或一组实例。 EC2 队列可以结合使用按需实例、预留实例和 Spot 实例购买模型,跨多个可用区启动多种实例类型。 使用 EC2 队列,您可以定义单独的按需和 Spot 容量目标,指定最适合您的应用程序的实例类型,并指定 Amazon EC2 应如何在每个购买模型中分配您的队列容量。

**YAML**
Type: AWS::EC2::EC2Fleet
Properties: 
  ExcessCapacityTerminationPolicy: String
  LaunchTemplateConfigs: 
    - FleetLaunchTemplateConfigRequest
  OnDemandOptions: 
    OnDemandOptionsRequest
  ReplaceUnhealthyInstances: Boolean
  SpotOptions: 
    SpotOptionsRequest
  TagSpecifications: 
    - TagSpecification
  TargetCapacitySpecification: 
    TargetCapacitySpecificationRequest
  TerminateInstancesWithExpiration: Boolean
  Type: String
  ValidFrom: String
  ValidUntil: String

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-ec2fleet.html

暂无
暂无

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

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