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.
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.
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.
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.
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.
You can do it through AWS console UI:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With