First get the Interface mac address, then use that to run the full command
INTERFACE=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/)
SUBNET_ID=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/subnet-id)
VPC_ID=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/vpc-id)
echo SUBNET_ID
Not sure this will work if you have more than one network interface
Thanks this help me. Here is the powershell version to get the VPC_ID.
$INTERFACE=$ (Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/network/interfaces/macs/)
$SUBNET_ID=$ (Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/network/interfaces/macs/$INTERFACE/subnet-id)
$VPC_ID=$ (Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/network/interfaces/macs/$INTERFACE/vpc-id)
$VPC_ID.content