Home > Blockchain >  Use EC2 instance ID in wordpress site
Use EC2 instance ID in wordpress site

Time:11-08

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?

CodePudding user response:

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.

CodePudding user response:

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

  • Related