我正在尝试使用CLI在ec2中创build一个实例。 有没有办法使用CLI创build实例时为实例指定标签?
aws ec2 run-instances --image-id $ami_id --key-name $deployment_key_name \ --region $region --security-groups default --instance-type m4.large \ --user-data file://./yaml/master.yaml
截至2017年3月28日,您可以为实例(和附加卷)指定标签,作为run-instances命令的一部分。
例:
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}]'
公告博客文章: https : //aws.amazon.com/blogs/aws/new-tag-ec2-instances-ebs-volumes-on-creation/
其他文档(请参阅示例4): http : //docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#Using_Tags_CLI
之后使用aws ec2 create-tags命令通过实例ID添加标签。