我的应用程序中有以下代码。
require 'aws-sdk'
require 'rubygems'
AWS.config({
:access_key_id => 'XXXXXXXXXXXXXXXXX',
:secret_access_key => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
})
ec2 = AWS::EC2.new(:ec2_endpoint => 'ec2.ap-southeast-1.amazonaws.com')
@@i = ec2.instances.create(:image_id => 'ami-aabXXXXX', :instance_type => 't1.micro', :security_groups=> ['Drum-Factory'], :key_name => 'some-key' )
sleep 1 while @@i.status == :pending
......
如何在创建实例时为其命名,以便它显示在我的AWS管理控制台的“名称”列中。
答案 0 :(得分:1)
名称列实际上是添加到实例的标记 所以你需要设置“名称”标签的值
我的猜测是这样的
@@i.tags["Name"] = "value"
或
tag = ec2.tags.create(@@i, "Name","Value")
检查http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/TagCollection.html#create-instance_method
这个SO答案也许会有所帮助 For AWS, how do you set tags to a resource with the ruby aws-sdk?