chaitu87
chaitu87

Reputation: 13

Create a name to a EC2 instance by using AWS API

I have the following code in my app.

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
......

How can i name my instance while creating it, so that it will appear in the Name column of my AWS Management Console.

Upvotes: 1

Views: 767

Answers (1)

Pritesh Jain
Pritesh Jain

Reputation: 9146

Name column is actually a tag added to the instance So you need to set the value of "Name" tag

My guess is something like this

@@i.tags["Name"] = "value"

or

tag = ec2.tags.create(@@i, "Name","Value") 

check http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/TagCollection.html#create-instance_method

also this SO answer might be of help For AWS, how do you set tags to a resource with the ruby aws-sdk?

Upvotes: 1

Related Questions