Jonathan Fischoff
Jonathan Fischoff

Reputation: 1487

How to set an instance name with right_aws

Is it possible to the set the name of an EC2 instance with right_aws like I can with the AWS Management Console?

Upvotes: 1

Views: 1485

Answers (2)

cloudartisan
cloudartisan

Reputation: 656

See 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

So to add a "Name" tag with the value "my_awesome_server" to instance "i-12345678":

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

That should be all there is to it.

Upvotes: 1

Eric Hammond
Eric Hammond

Reputation: 22407

EC2 as a service does not have a built in concept of names for instances as it does for, say, AMI names.

The concept of an instance name is generally implemented as a tag on the instance with a specific key.

Different UIs might use different tag keys to determine the name of the instance, but there is a somewhat de facto standard using of using the tag "Name" as this is what the AWS console uses.

If your tools support setting tags, then you can set the "Name" tag to your desired value and it will show up in the appropriate column in the AWS console.

Instance tags were released September 19, 2010, so you'll need to use a version of your software that came out at some point after that.

Upvotes: 2

Related Questions