Reputation: 4230
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.
Upvotes: 35
Views: 43672
Reputation: 2635
In 2021 this can be done from the AWS console, by going to EC2 > Instances, clicking the instance ID, then in the bottom panel clicking on the Tags tab, and clicking Manage tags. From there, you can simply change the value of the Name tag then click Save to apply.
Upvotes: 15
Reputation: 2371
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.
Upvotes: 35
Reputation: 4230
Further digging into the API and I found what I was looking for.
These are known as tags. You can assign them to nearly any aws entity (some things are excepted, e.g., you can't add a tag to an elastic ip).
You can set keyname/keyvalue pairs through the API. Documentation is here: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateTags.html
Then you can filter results by these tags, or choose to display them in the web interface.
Upvotes: 4