hel*_*loV 1 amazon-ec2 amazon-web-services aws-cli
如果要在启动时为实例添加标签,则必须执行两个步骤:
run-instances)create-tags)有没有办法在使用单个 CLI 命令启动实例时添加标签(或设置名称)?
此请求已等待很长时间,AWS 终于在March 2017.
请参阅:Amazon EC2 和 Amazon EBS 添加了对在创建时标记资源和其他资源级权限的支持
确保您的 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
Run Code Online (Sandbox Code Playgroud)
以下示例将具有键为
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}]'
Run Code Online (Sandbox Code Playgroud)
该命令还将一个键为
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}]'
Run Code Online (Sandbox Code Playgroud)