I’m trying to get ec2 instance id and assign it into environment variable with a script.
I found some command that supposed to give me the id but they don’t work.
The curl
command returns nothing:
curl command,
I tried this way also: export INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id
, but the variable is empty.
The cat /sys/devices/virtual/dmi/id/board_asset_tag
command prints the id, but when I try to assign it to the variable, I get Permission Denied error.
Any ideas why curl returns nothing, or any other way to get the instance id?
Thanks
2
Answers
If you have cloud-utils on your machine, you can try
As per comment the problem was solved by using the ec2-metadata tool
On the Amazon Linux AMI, there is a tool already pre-installed called ec2-metadata which can be run from the command line interface (CLI).
If its other than amazon ami then install it first and then use it