简体   繁体   English

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

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

I want to launch more than one Ec2 instances using aws cloudformation template without using AutoScaling.我想在不使用 AutoScaling 的情况下使用 aws cloudformation 模板启动多个 Ec2 实例。 Please let me know how can I launch?请让我知道如何启动?

There are several ways to launch multiple instances using CloudFormation without having Autoscaling Group in place.在没有 Autoscaling Group 的情况下,有多种方法可以使用 CloudFormation 启动多个实例。

  1. Create required number of resources in same Cloudformation template.在同一 Cloudformation 模板中创建所需数量的资源。 Eg.例如。 If you want to launch 3 instances then you must write the code to launch 3 AWS instances in your Cloudformation Template.如果要启动 3 个实例,则必须编写代码以在 Cloudformation 模板中启动 3 个 AWS 实例。

Following template has 2 resource which will launch 2 EC2 instance.以下模板有 2 个资源,将启动 2 个 EC2 实例。 You can add more resources as per requirement.您可以根据需要添加更多资源。

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. Create multiple Cloudformation Stacks using same Cloudformation template.使用相同的 Cloudformation 模板创建多个 Cloudformation 堆栈。 Eg.例如。 You have to create 2 Cloudformation stacks from same Cloudformation template which has Resource to launch 1 EC2 instance each.您必须从相同的 Cloudformation 模板创建 2 个 Cloudformation 堆栈,该模板具有每个启动 1 个 EC2 实例的资源。

Following template has 1 resource which will launch 1 EC2 instance.以下模板有 1 个资源,将启动 1 个 EC2 实例。 As per 2nd method, you can create multiple Cloudformation stacks using same template to get multiple EC2 instances.按照第二种方法,您可以使用相同的模板创建多个 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

Try using Type: AWS::EC2::EC2Fleet尝试使用类型: AWS::EC2::EC2Fleet

You can specifies a configuration information to launch a fleet--or group--of instances.您可以指定配置信息以启动一组或一组实例。 An EC2 Fleet can launch multiple instance types across multiple Availability Zones, using the On-Demand Instance, Reserved Instance, and Spot Instance purchasing models together. EC2 队列可以结合使用按需实例、预留实例和 Spot 实例购买模型,跨多个可用区启动多种实例类型。 Using EC2 Fleet, you can define separate On-Demand and Spot capacity targets, specify the instance types that work best for your applications, and specify how Amazon EC2 should distribute your fleet capacity within each purchasing model.使用 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 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-ec2fleet.html

暂无
暂无

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

相关问题 如何使用EC2刀启动多个实例 - How to launch more than one instance using knife ec2 在AWS CloudFormation中,是否可以使用Mappings中没有AutoScaling组的值创建多个EC2实例? - In AWS CloudFormation is it possible to create a number of EC2 instances with the values from Mappings without AutoScaling group? 如何使用Terraform配置AWS自动伸缩组/启动配置以仅在一个EC2实例上运行cron作业? - How can I configure an AWS autoscaling group/launch configuration with Terraform to only run a cron job on one EC2 instance? 无法使用 terraform 向 AWS ELB 添加多个 ec2 实例 - Cannot add more than one ec2 instances to AWS ELB using terraform 如何使用 AWS CLI 获取具有特定标签的 Amazon EC2 自动扩展组中的实例? - How to get the instances in the Amazon EC2 autoscaling group with specific tags using AWS CLI? 如何使用 Jenkins 将应用程序部署到 EC2 实例(具有自动缩放功能)? - How to deploy an application to EC2 instances(with Autoscaling) using Jenkins? 如何使用AWS Cli启动具有自定义根卷ebs大小(大于8GB)的ec2实例 - How to launch ec2 instance with custom root volume ebs size (more than 8GB) using AWS Cli 如何在 AWS Lambda 中使用 Node.js 列出我的所有 Amazon EC2 实例? - How can I list all my Amazon EC2 instances using Node.js in AWS Lambda? 如何使用 AWS CDK 从 EC2 Autoscaling Group 获取 EC2 ID 和私有 IP - How to get EC2 ID and Private IP from EC2 Autoscaling Group using AWS CDK 如何使用 Terraform 从单个 VPC 启动多个 AWS EC2 实例? - How to launch multiple AWS EC2 instances from a single VPC using Terraform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM