google-cloud-platformjupyter-notebookgoogle-cloud-ai

GCP AI platform API


I am trying to programatically create "AI Platform Notebooks" in GCP. The gcloud sdk does have some support for managing these notebooks, but not creating them. And there is no client library for support for Node.js (the language I'm using). Creating notebooks is however supported by the GCP REST API as documented here. However, I am struggling to work out how to specify what notebook I want in the request's JSON. From the GCP web UI, the settings I want are:

But I am struggling to translate this into a JSON request for the REST API. Below is what I have so far. I am not sure any of it is correct, and I'm definitely missing the environment (tensorflow 2.1) and single user only access. I have no idea how to go about achieving this other than randomly trying different requests until it works. (I have left some of the JSON as just specifying the types as per the docs for now, for reference).

POST https://notebooks.googleapis.com/v1beta1/projects/my-project/locations/europe-west2/instances
{
  "name" : "testing-instance",
  "instanceOwners": [
    string
  ],
  "serviceAccount": "team@project.iam.gserviceaccount.com",
  "machineType": "e2-highmem-2 (Efficient Instance, 2 vCPUs, 16 GB RAM)",
  "acceleratorConfig": {
    object (AcceleratorConfig)
  },
  "state": enum (State),
  "installGpuDriver": boolean,
  "customGpuDriverPath": string,
  "bootDiskType": enum (DiskType),
  "bootDiskSizeGb": string,
  "dataDiskType": enum (DiskType),
  "dataDiskSizeGb": string,
  "noRemoveDataDisk": boolean,
  "diskEncryption": enum (DiskEncryption),
  "kmsKey": string,
  "noPublicIp": boolean,
  "noProxyAccess": boolean,
  "network": string,
  "subnet": string,
  "labels": {
    string: string,
    ...
  },
  "metadata": {
    string: string,
    ...
  },
  "createTime": string,
  "updateTime": string,

  // Union field environment can be only one of the following:
  "vmImage": {
    object (VmImage)
  },
  "containerImage": {
    object (ContainerImage)
  }
  // End of list of possible types for union field environment.
}

Solution

  • Here the required JSON

    {
      "name": "testing-instance",
      "machineType": "zones/europe-west2-a/machineTypes/e2-highmem-2",
      "guestAccelerators": [],
      "metadata": {
        "items": [
          {
            "key": "proxy-mode",
            "value": "mail"
          },
          {
            "key": "framework",
            "value": "TensorFlow:2.1"
          },
          {
            "key": "proxy-user-mail",
            "value": "firstname.surname@email.com"
          }
        ]
      },
      "disks": [
        {
          "boot": true,
          "autoDelete": true,
          "initializeParams": {
            "diskType": "zones/europe-west2-a/diskTypes/pd-standard",
            "diskSizeGb": "100",
            "sourceImage": "projects/deeplearning-platform-release/global/images/family/tf2-2-1-cu101-notebooks-debian-9"
          }
        }
      ],
      "scheduling": {
        "onHostMaintenance": "MIGRATE"
      },
      "networkInterfaces": [
        {
          "subnetwork": "https://www.googleapis.com/compute/v1/projects/gbl-imt-homerider-basguillaueb/regions/europe-west2/subnetworks/datalab-network",
          "accessConfigs": [
            {
              "name": "external-nat",
              "type": "ONE_TO_ONE_NAT"
            }
          ]
        }
      ],
      "serviceAccounts": [
        {
          "email": "team@project.iam.gserviceaccount.com",
          "scopes": [
            "https://www.googleapis.com/auth/cloud-platform",
            "https://www.googleapis.com/auth/userinfo.email"
          ]
        }
      ],
      "tags": {
        "items": [
          "deeplearning-vm"
        ]
      }
    }
    
    

    Impossible to guess by yourselves. How I do? Do it with the console and before submitting, open the Chorme debugger and capture the network request. The post request contain this JSON!

    Enjoy