I'm writing a bash script that needs to use the instance's public dns name. What's the easiest way to obtain it from inside the running instance?

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

You can fetch data about the running instance from a little http API using curl like this:

#/bin/bash
public_name=$(curl -s http://169.254.169.254/latest/meta-data/public-hostname)
echo $public_name

Other values you can fetch include:

  • ami-id
  • hostname
  • instance-id
  • local-ipv4
  • local-hostname
  • public-hostname
  • public-ipv4

There are more but those are some of the most useful. Things like the SSH keys you specify at instance launch can also be retrieved from there.

link|improve this answer
1  
Note that the DNS name for that API is instance-data.ec2.internal if you'd prefer to use that. – ceejayoz Jun 10 '11 at 20:24
feedback

Your Answer

 
or
required, but never shown

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