Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2: How can I get the Vpc ID of an Instance?

I am trying to find out the vpc-id of an instance. Can anyone refer to an API that would work this out? Im using the java sdk.

like image 292
ihsan Avatar asked Dec 09 '22 04:12

ihsan


1 Answers

You can try doing the below one inside the ec2-instance

First you need to find the macid of the instance

macid=$(curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/)

and use the macid below

curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/${macid}/vpc-id

like image 149
santhosh Avatar answered Dec 10 '22 16:12

santhosh