如何在不使用 AutoScaling 的情况下使用 aws cloudformation 启动多个 EC2 实例?
How can I launch more than one EC2 instances using aws cloudformation without using AutoScaling?
我想在不使用 AutoScaling 的情况下使用 aws cloudformation 模板启动多个 Ec2 实例。
请告诉我如何启动?
有多种方法可以使用 CloudFormation 启动多个实例,而无需安装自动缩放组。
- 在同一 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
- 使用相同的 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
我想在不使用 AutoScaling 的情况下使用 aws cloudformation 模板启动多个 Ec2 实例。 请告诉我如何启动?
有多种方法可以使用 CloudFormation 启动多个实例,而无需安装自动缩放组。
- 在同一 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
- 使用相同的 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