2011-11-01 33 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設置標籤嗎? –