Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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.

1 Answer

0 votes
by (44.4k points)

Use this (This is completely a single file):

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);

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories

...