skip to Main Content

I have an autoscaling group launching different EC2 instances, each running the same wordpress application. Somewhere on the wordpress page (let’s call it home.html), I want to show the EC2 instance id. I can grab the instance id using this curl command: curl http://169.254.169.254/latest/meta-data/instance-id.

Is there a way I can show the instance id using this curl command, or any way I can set an html variable dynamically to display this metadata on the page?

2

Answers


  1. You can just make a HTTP request to GET any Metadata by passing the your metadata parameters.

    curl http://169.254.169.254/latest/meta-data/instance-id
    

    or

    wget -q -O - http://169.254.169.254/latest/meta-data/instance-id
    

    You can find more meta-data here.

    Login or Signup to reply.
  2. You could put something like this in your PHP template where you want to display the instance ID:

    <?php echo file_get_contents("http://169.254.169.254/latest/meta-data/instance-id"); ?>
    

    This will display the current instance id whenever the page is loaded

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search