2011-11-01 38 views

回答

1

https://github.com/rightscale/right_aws/blob/master/lib/ec2/right_ec2_tags.rb

# Add a single tag with no value to a resource: 
# ec2.create_tags("i-12345678", "myKey") => true 
# 
# Add multiple tags with no values (actually Amazon sets the values to '') 
# ec2.create_tags("i-12345678", ["myKey1", "myKey2", "myKey3"]) => true 
# 
# Add multiple tags with 'true' 
# ec2.create_tags("i-12345678", ["myKey1", "myKey2", "myKey3"], :default => true) => true 
# 
# Add multiple keys and values to a resource: 
# ec2.create_tags("i-12345678", {"myKey1" => "foo", "myKey2" => "bar", "myKeyWithoutVal" => nil }) #=> true 
# 
# Add a key and value to multiple resources: 
# ec2.create_tags(["i-12345678","i-86fb3eec","i-86fb3eed"], {"myKey" => "foo"}) #=> true 

所以要加一个 “名称” 标签与价值 “my_awesome_server”,以实例的 “i-12345678”:

ec2 = RightAws::Ec2.new(aws_access_key_id, aws_secret_access_key) 
ec2.create_tags("i-12345678", {"Name" => "my_awesome_server"}) 

这应该是所有有它。

+0

对于这个例子,如果应该是“名称”@Eric Hammond指出 –

+0

标签可以是任何你想要的。然而,“名称”是名称的惯例。编辑。 – cloudartisan

2

EC2的服务不具有一个内置的名字的概念,因为它,比如说,AMI名实例。

实例名称的概念通常实现为与特定键上的实例的标签。

不同的UI可以使用不同的代码键来确定实例的名称,但是有几分事实标准使用使用标签“名”,因为这是AWS控制台使用什么的。

如果你的工具支持设置标签,那么你可以在“名称”标签设置为你想要的值,它会在AWS控制台相应的列中显示。

实例标签被2010年9月19日发布的,所以你需要使用一个版本的软件,在之后的某个时候就出来了。

+0

你知道如何用right_aws设置标签吗? –