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:
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_CERT) or set (
-C) the path to your private key and certificate files.
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 http://169.254.169.254/latest/meta-data/