Tutorial: VS Code with Google Cloud AI Platform as a backend

Kyle Ziegler
3 min readMar 31, 2021

--

In this tutorial, we’ll setup VS Code, your local environment, and an AI Platform Notebook. This gives you a few benefits, including using your local git credentials, local IDE extensions, and a smoother user experience. You’ll also be able to drag and drop items from your local machine, or use the terminal in VS Code to access your GCS buckets.

Using bullets here because Medium won’t let you have a numbered list and insert images without breaking the list order!

  • Install the gcloud SDK & VS Code. Self explanatory.
  • Install Remote-SSH VS Code extension
  • Authenticate into your GCP project via the gcloud auth command on your local terminal
  • Create an AI Platform Notebook — note that you’ll want to choose a machine that is in a region close to your data (ie storage buckets in us-west) for optimal performance. We want to use an “Instance” here and not a managed notebook (managed notebooks don’t have an external IP).
  • (optional) Reserve a static external IP for your notebook
    This makes it a lot easier to SSH into your instance, you won’t have to update your SSH config everytime you connect. Default is an ephemeral IP. Navigate to Network -> VPC -> External IP Addresses -> Select the notebook instance name to assign a IP to.
  • If your notebook is always running, you can skip this step as well.
  • Set up your local ssh config with the correct IP and username (jupyter)
  • Copy your google cloud compute public key (local) into a file named ./ssh/authorized_keys in the jupyter home folder.
  • We only need to do this for the jupyter user. Note that when VMs are created, user metadata is copied on start, which includes your primary login (name@domain.com). However, the ssh keys are not copied to the jupyter user, and that is the user that is used when you log into the notebook via the AI Platform UI. If you don’t plan on logging into the notebooks from the console, you could just use your default user (update your ssh config appropriately)
  • SSH from VS Code — command + shift + p to open the command pallet, start typing ssh and select connect to host.
  • Once you’re in you’ll see your instance name in the bottom left of the editor
  • Navigate to the top left and open the jupyter home folder
  • You are now good to go! I’ve included some more optional steps below depending on what you are working on
  • (optional) Install ipynb extension to edit notebooks

I hope you enjoyed the tutorial and that it saved you some time in getting your local environment working with a Cloud AI Platform Notebook! Feel free to reach out if you’d like to see a specific tutorial on anything AI Platform related.

Useful links:

--

--

Kyle Ziegler
Kyle Ziegler

Written by Kyle Ziegler

ML Software Engineer @ YouTube

Responses (1)