In the web console there is a field "Name" which you can edit to associate useful context with an instance, is there a way to set or retrieve this info from the command line?


Yes, you can use the command line tools to view this information, if you need to parse this information out, you will be better off using the API (as it is both far faster and the information is much easier to work with).

From the command line tools, run: ec2-describe-instances

You will find a line that reads similar to the following:

TAG     instance        i-xxxxxxxx      Name    MyTagName

For a cleaner readout, you might want to pipe the output through grep:

ec2-describe-instances | grep TAG

Don't forget to export (EC2_PRIVATE_KEY, EC2_CERT) or set (-K, -C) the path to your private key and certificate files.

  • Ah yes, you just have to update to a newer version of ec2-command-line-tools than I was using. Now that I've done that I can see that the name is just a tag.
    – Jamie Cook
    Jul 26 '11 at 3:52
  • when you say "use the API" what do you mean... i have only ever used the command line tools to work with the api?
    – Jamie Cook
    Jul 26 '11 at 3:55
  • API = application programming interface - essentially a way for software to interact with their service. AWS publishes these, and have made SDKs accessible in various languages - so, for instance, if you want to use PHP or Ruby, you can directly access and manipulate AWS data (e.g. lists of instances, etc.) without having to execute the command line tools (java based, and very slow) and parse the data. I, personally, like the Perl one for scripting - although it lacks some newer features.
    – cyberx86
    Jul 26 '11 at 4:04
  • ah when you said "the api" I thought there was one API to rule them all :) I tried the ruby one a while back and found it a bit lacking so switched to the linux command line tools instead.
    – Jamie Cook
    Jul 26 '11 at 5:42
  • There is 'one API', it has different versions, but the API itself is what AWS understands (SOAP and HTTP (GET/POST) requests) - AWS (and others) have written libraries to use the API in different languages - so you don't have to write the full request, just issue a command. The SDKs not maintained by AWS (e.g. Perl) are not always up-to-date. The AWS ones are pretty good though. For instance, the PHP one supports the 2011-05-15 API of EC2, which is the latest.
    – cyberx86
    Jul 26 '11 at 5:58

You can set the Name of an instance using the command line tools with this command

ec2addtag i-??????? --tag Name=my-fancy-name
  • This is the only answer that answers the question of how to set the instance name. Jan 15 '15 at 15:52

You can use the aws command to set the name of an instance like so:

aws ec2 create-tags --resources i-??????? --tag Key=Name,Value="MY INSTANCE NAME"

Also note that there are other ways to get data about an instance from an instance:

/usr/bin/curl –s


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.