amazon-web-services - 如何在不使用 AutoScaling 的情况下使用 aw

我想使用 aws cloudformation 模板启动多个 Ec2 实例,而不使用 AutoScaling。 请告诉我如何启动?

最佳答案

有多种方法可以使用 CloudFormation 启动多个实例,而无需安装 Autoscaling Group。

  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

关于amazon-web-services - 如何在不使用 AutoScaling 的情况下使用 aws cloudformation 启动多个 EC2 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46557710/

相关文章:

php - 使用 symfony 文件系统代替原生 PHP 的优势

php - 使用 Laravel 5.2 集合中的列名获取唯一值的计数

r - 在 R 中制作特定的分位数图

node.js - 在 Node.js 中生成唯一 ID 的最佳方法是什么?

wpf - 字符串格式正值和负值以及条件颜色格式 XAML

sql - Oracle SQL - 从给定的字符串形成一个虚拟表以与另一个表连接

c# - 蓝牙扫描C#

php - 删除 wordpress 站点中超过 2 年的帖子

Python 2.7 - 如何检查是否按下了 SHIFT-Key 或 CTRL+Key?

julia - 为什么 Julia 闭包不复制数组?