Search code examples
google-cloud-platformgcp-ai-platform-notebook

Is it possible to obtain instance metadata for GCP on Google Collaboratory?


I'm trying to obtain instance metadata on Google Collaboratory. I'm interested in finding out the compute region.

Specifically, on the hosted runtime on Google Collaboratory, I tried running the following commands but they time out.

!curl "http://metadata.google.internal/computeMetadata/v1/?recursive=true&alt=json" -H "Metadata-Flavor: Google"

curl: (7) Failed to connect to metadata.google.internal port 80: Connection timed out
!curl "http://169.254.169.254/computeMetadata/v1/instance/?recursive=true&alt=json" -H "Metadata-Flavor: Google"

curl: (7) Failed to connect to 169.254.169.254 port 80: Connection timed out

Am I doing something incorrectly, or are there any other workarounds for this?

Thank you!


Solution

  • you cannot access the metadata server from outside of Google Cloud Platform as it's something specific of the Google Compute Engine (GCE).

    In order to know the compute region you can link together your Google Collaboratory notebook with an instance VM in the GCE, then your notebook will run in that specific instance VM.

    Another way is using the AI platform notebooks instead of Google Collaboratory, as this uses the GCE as a backend.