【问题标题】:How to create an aws instance using an instance template in the aws cli如何在 aws cli 中使用实例模板创建 aws 实例
【发布时间】:2021-09-03 12:34:58
【问题描述】:

如何从 aws 上的实例模板中创建具有所选名称的实例。

以前我在谷歌云上时,首先我创建了一个实例模板,例如它被称为node-template

要创建服务器,我会在 gcloud cli 中使用以下命令,

gcloud instances create node-1 --source-instance-template=node-template
gcloud instances create node-2 --source-instance-template=node-template
gcloud instances create node-3 --source-instance-template=node-template
....

aws 是否可以实现类似的功能?

我基本上需要创建多个具有相似规格的实例,并且能够每天启动它们、通过 SSH 连接它们并停止它们。

【问题讨论】:

    标签: amazon-web-services google-cloud-platform command-line-interface


    【解决方案1】:

    AWS CLI 命令aws ec2 run-instances 可用于启动 Amazon EC2 实例。见:run-instances — AWS CLI Command Reference

    该命令允许以 JSON 格式指定所有参数,这可以来自磁盘:

    aws ec2 run-instances --cli-input-json file://my-parameters.json
    

    见:Loading AWS CLI parameters from a file - AWS Command Line Interface

    或者,您可能想要Launch an instance from a launch template - Amazon Elastic Compute Cloud,这是存储在您的 AWS 账户中的 Amazon EC2 实例的预定义定义。然后,您可以在启动实例时引用此启动模板:

    aws ec2 run-instances --launch-template LaunchTemplateName=MY-LAUNCH-TEMPLATE
    

    可以通过指定Name 标签来分配实例名称:

    aws ec2 run-instances --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=MY-INSTANCE-NAME}]' --launch-template LaunchTemplateName=my-launch-template
    

    【讨论】:

    猜你喜欢
    • 2018-07-02
    • 2020-03-20
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多