AWS EC2:使用CLI启动实例时添加标记

时间:2017-07-27 05:22:16

标签: amazon-web-services amazon-ec2 aws-cli

如果要在启动时向实例添加标记,则必须执行两个步骤:

  1. 启动实例(run-instances
  2. 将标记添加到新创建的实例(create-tags
  3. 使用单个CLI命令启动实例时,是否可以添加标记(或设置名称)?

1 个答案:

答案 0 :(得分:3)

这个请求已经存在很长时间了,AWS终于在March 2017中支持了这个。

请参阅:Amazon EC2 and Amazon EBS add support for tagging resources upon creation and additional resource-level permissions

确保您的AWS CLI版本至少为 1.11.106

$ aws --version
aws-cli/1.11.109 Python/2.6.9 Linux/4.1.17-22.30.amzn1.x86_64 botocore/1.5.72

<小时/> 启动时标记实例的CLI:

  

以下示例应用密钥为webserver和的标记   production对实例的值。

aws ec2 run-instances --image-id ami-abc12345 --count 1 --instance-type t2.micro 
    --key-name MyKeyPair --subnet-id subnet-6e7f829e
    --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]'

<小时/> 用于标记实例和卷的CLI:

  

该命令还应用密钥为cost-center的标记和值   cc123对任何创建的EBS卷(在本例中为根)   体积)。

aws ec2 run-instances --image-id ami-abc12345 --count 1 --instance-type t2.micro 
    --key-name MyKeyPair --subnet-id subnet-6e7f829e
    --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]' 'ResourceType=volume,Tags=[{Key=cost-center,Value=cc123}]'