1

是否可以像使用 AWS 管理控制台一样使用 right_aws 设置 EC2 实例的名称?

4

2 回答 2

2

EC2 as a service 没有内置的实例名称概念,例如 AMI 名称。

实例名称的概念通常实现为具有特定键的实例上的标记。

不同的 UI 可能使用不同的标签键来确定实例的名称,但是使用标签“名称”在某种程度上是事实上的标准,因为这是 AWS 控制台使用的。

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

实例标签于 2010 年 9 月 19 日发布,因此您需要使用在此之后发布的软件版本。

于 2011-11-02T00:54:08.127 回答
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"})

这应该就是它的全部了。

于 2011-11-04T11:14:03.380 回答