Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify the instance name for an ec2 instance

Tags:

I would like to modify the "name" attribute of an amazon instance. See attached screenshot. I need to do it programmatically, but can't find anywhere in the EC2 API how to set that.

If it matters, I'm launching these via a spot request through their API. I would like to set the field that I tagged, "set this name" in the image below.

screen shot of field to set

like image 252
Travis Leleu Avatar asked Jun 02 '11 20:06

Travis Leleu


People also ask

How do I rename an EC2 instance?

You can rename an EC2 instance by editing the "Name" tag on your EC2 instance. If a Name tag does not exist and your EC2 is currently nameless, you can just create a new tag with key "Name". Save this answer.

How do I edit an instance?

Click the instance ID of the instance you want to edit. On the Instance details page, click Edit to go to the Edit instance page. Change the instance description, IP-based access control rules, and capacity as needed. For details, see Creating instances.

Can you change EC2 instance ID?

So if you have an existing EC2 instance, it's instance ID will not change. Once you opt-in, when you create a new EC2 instance, that new EC2 instance can and/or will have a longer instance ID. Only the creation of new resources are affected.


2 Answers

This might help...

AmazonEC2 ec2;     AWSCredentials credentials; String accKey = "your access key"; String secKey = "your secret key";      credentials = new BasicAWSCredentials(accKey, secKey); ec2 = new AmazonEC2Client(credentials);  String instanceId = "Your Instance ID"; List<Tag> tags = new ArrayList<Tag>();  Tag t = new Tag(); t.setKey("Name"); t.setValue("my server!"); tags.add(t);  Tag t = new Tag(); t.setKey("owner"); t.setValue("me"); tags.add(t);  CreateTagsRequest ctr = new CreateTagsRequest(); ctr.setTags(tags); ctr.withResources(instanceId); ec2.createTags(ctr); 

kind of quick and dirty, but you get the idea.

like image 73
Kevin Mansel Avatar answered Oct 20 '22 00:10

Kevin Mansel


You can do it through AWS console UI:

ec2

like image 27
Oleksandr Masovets Avatar answered Oct 19 '22 23:10

Oleksandr Masovets