Photo by Niklas Tinner on Unsplash

Google Cloud Platform (GCP)

Build Your Castles In The Sky

Set up a powerful remote development environment on Google’s new Cloud Workstations

Benjamin Engen
Google Cloud - Community
9 min readJan 10

Google recently released a new addition to Google Cloud Platform into public beta called Cloud Workstations. Their answer to Amazon’s Cloud9. Cloud Workstations provide a lightweight, cheap, virtual machine specifically for development work. Below I’ll cover the detailed steps involved in setting up your first Cloud Workstation, connecting your local VSCode instance to it via SSH, and configuring your Workstation for Python development.

  1. Why Google Cloud Workstations?
  2. Creating Your Google Cloud Project
  3. Creating Your Google Cloud Workstation
  4. Connecting to Your Google Cloud Workstation
  5. Configuring Your Google Cloud Workstation

If you found this guide useful and/or you’re interested in more detailed getting-started guides please follow me here on Medium.

Why Google Cloud Workstations?

I use Google Cloud Workstations for my personal projects as it offers one big advantage over developing locally on my laptop — performance. Specifically when I need more:

  1. Bandwidth
  2. Processing Power

Like most of us working in data, my work is focused on wrangling messy data into something queryable and usable. In my case, this often involves sizable file transfers from source FTP servers. Speaking as a remote worker from before it was cool I can tell you, performing big file transfers to your laptop over the free Starbuckswifi is not ideal. Much better to let Google’s robust infrastructure transfer these files to one of its servers and work with it from there.

Bandwidth aside, there’s the more obvious performance component of sheer processing power. My slavish devotion to my 2013 laptop means my local development environment is easily outclassed by one of Google’s 8-CPU Cloud Workstations.

Lastly, I appreciate the seamless experience. Connecting my local instance of VS Code to my Google Workstation via SSH means I preserve the functionality and feel of the coding environment I’ve grown accustomed to while still being able to take advantage of the aforementioned bandwidth and power.

So, let’s get you set up to try it out for yourself.

Creating Your Google Cloud Project

Google Cloud Platform project creation screen
Screenshot 1 by Author

Assuming you’re starting from scratch, head over to: https://console.cloud.google.com/

  1. Click the drop-down on the top-left and then choose “New Project” as shown in Screenshot 1.
  2. Enter a “Project name” for your project. It’s considered good practice to append some numbers to the name you choose. For this example, I’m choosing “gcp-workstations-8379”
  3. Choose an “Organization” and “Location” from the dropdowns. If you’re just starting out you should only have one option available for each.
  4. Click the blue “Create” button.
  5. It will take a minute for your project to create. Once it does you can select it from the same top-left drop-down shown in Screenshot 1 that you accessed to create the project.

Creating Your Google Cloud Workstation

Google Cloud Platform search bar
Screenshot 2 by Author
  1. “Search” for “Workstations.” In the search bar at the top of the screen type “Workstations” and choose the “Cloud Workstations” option that populates in the drop-down.
  2. Click the blue “Enable” button. You’ll need to enable the Cloud Workstations API on this project which is as easy as clicking the button to do so.
  3. Choose “Clusters” from the menu on the left as shown in Screenshot 3. Creating the workstation requires three steps: creating a cluster, a configuration, and then the workstation.
Google Cloud Platform Workstations space
Screenshot 3 by Author

4. Click the blue “Create Cluster” button.

5. Choose a “Name” for your cluster. I’ll call mine “demo-cluster-101”.

6. Choose a “Region” for your cluster’s location. It’s good practice to co-locate your cluster in the same region as other Google Cloud resources it might utilize or near users (in this case: you). I’ll choose “us-west1” for mine.

There’s a drop-down for advanced settings. This contains configuration options in the event that you’re adding this workstation to a new/existing VPC (Virtual Private Cloud) network. Since we’re assuming a start from scratch you can ignore this section.

7. Click the blue “Create” button. Cluster creation is the most time-consuming step and can take up to 20 minutes to complete. So… go make a coffee or something.

8. Choose “Configurations” from the same left-hand menu shown in Screenshot 3.

9. Click the blue “Create Configuration” button. The true intention of Cloud Workstations is to give organizations a consistent development environment for their developers. In this step, we’ll create a configuration that can be applied to many individual workstations.

10. Enter a “Name”, I’ll choose “gcp-demo-config-202”

11. Choose a “Cluster” from the drop-down. Your only option should be the cluster we just created in Step 7.

12. Choose “Disabled” under “Quick start workstations.” I choose this because it’s cheaper, but feel free to enable this option if you’re impatient.

13. Click “Continue.”

14. Chose a “Machine type.” I’ll choose the default “e2-standard-4" which is a 4-CPU 16GB virtual machine.

15. Choose an “Auto-sleep” option. I’ll choose the default, “After 2 hours of inactivity” here as well.

16. Click “Continue.”

You’re now in the “Environment customization” section which is the most important step. Here you can choose the environment and IDE you’d like to build your workstation around. For this example, we’re going to use “Code editors on base images” and choose “Base Editor (Code OSS)” which is basically VS Code. If you are actually using this for an organization and intend to have several users I’d strongly advise choosing “Custom container image” instead. However, that is beyond the scope of this introduction.

17. Choose the “Code editors on base images” radio button.

18. Choose “Base Editor (Code OSS)” from the “Code editors” drop-down.

19. Choose a “Disk type” from the drop-down. I’ll choose “Standard.”

20. Choose an option for “Disk size” from the drop-down. I’ll choose the default “200 GB.”

21. Click the blue “Create” button.

22. Choose “Workstations” from the left-hand menu as shown in “Screenshot 3” above.

23. Click the blue “Create workstation” button.

24. Enter a “Name” for your workstation. I’ll choose “gcp-demo-workstation-303”

25. Choose a “Configuration” from the dropdown. Your only option should be the one we just created.

26. Click the blue “Create” button.

Your virtual workstation is now created.

Connecting to Your Cloud Workstation

Google Cloud Workstations connection details
Screenshot 4 by Author

Cloud Workstations make connection and use very simple. If you like you can simply launch a window in your web browser and begin right away. However, I prefer to use my local version of VS Code which requires establishing an SSH connection. We’ll cover both options here.

Connecting via Browser

  1. Click “Start” which should occupy the area in the blue box shown in Screenshot 4.
  2. Click “Launch” once the “Start” button converts to this option. This will open your workstation-hosted instance of VS Code in a new browser tab and you’re good to go.

Connecting via SSH

Connecting via SSH using the below will require having the Google Cloud CLI installed on your machine.

  1. Head to https://cloud.google.com/sdk/docs/install, download, and install the appropriate version of the Cloud CLI for your machine.
  2. Launch the Google Cloud CLI. If you’re on windows you probably have this icon on your desktop now.
  3. Enter the command gcloud auth login. This should open a web browser and prompt you to log in using the Google account you’re using to access Google Cloud Platform.
  4. Once authenticated, return to the Cloud Workstation home screen as shown in “Screenshot 4” and click the drop-down arrow next to the “Launch Button” then choose “Connect using SSH…” This will bring up a window as shown in “Screenshot 4” that provides the Google Cloud CLI command necessary to establish the TCP tunnel to your Workstation.
  5. Run the top command in the Google Cloud CLI. There is a newer version of this command available so I recommend replacing gcloud alpha workstations with gcloud beta workstations but the rest of the command which contains your individual workstation information should remain unchanged. You may receive a notification that alpha/beta commands are not available in your Google Cloud CLI install. If that happens, it should also prompt you to download that functionality. Once you successfully run the gcloud beta workstations…command it should return Listening on Port 2222.
  6. Open your local version of VS Code.
VS Code ssh connection palette
Screenshot 5 by Author

7. In VS Code hit Ctrl + Shift + P to open the command palette.

8. Type “Open SSH Configuration File” and choose that option when it populates in the drop-down. If you’re on windows the file should be something like C:\Users\user\.ssh\config

9. Enter the below into the file:

# GCP Workstation
Host gcp
HostName localhost
user user
port 2222
StrictHostKeyChecking no

10. Save and close the config file.

11. Hit Ctrl + Shift + P to open the command palette.

12. Type “Connect to Host” and choose the option “Remote-SSH: Connect to Host…” from the dropdown.

13. Choose “gcp” from the next drop-down menu.

14. During setup it might prompt you to ask about the environment you’re connecting to. Choose “Linux”

Troubleshooting:

If you have trouble connecting, or reconnecting, to your workstation it could be a problem with the “StrictHostKeyChecking” that we attempted to disable in the initial configuration. If this happens find the file known_hosts which on Windows should reside at c:\Users\user\.ssh\known_hosts open this file in notepad. Look for [localhost]:2222 and delete this text along with everything following it. Save and close the file and then try to connect in VS Code again.

Configuring Your Google Cloud Workstation

As we’ve created our Cloud Workstation from the base image we now need to configure our environment. As I mentioned after Step 16 in the “Creating Your Google Cloud Workstation” section, if you’re going to have multiple Workstations it would likely be best to carry out these steps in a Dockerfile that you attach to your Configuration and then build subsequent Workstations from that configuration. As this example is for individual use we’ll just carry out these steps once our Workstation is live.

Below are the steps to configure your environment for Python.

  1. Assuming you’re connected via SSH from your local instance of VS Code as per the end of the previous section go to “Terminal” at the top and then choose “New Terminal.” A terminal should open at the bottom with a bash prompt including your workstation name. In my case the prompt is user@gcp-demo-workstation-303: Make sure yours is something similar.
  2. In the terminal enter sudo apt update && sudo apt upgrade -y
  3. Once the upgrades are finished enter sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev This step is particularly important for Python. If prompted “Do you wish to continue?” Type Y
  4. Choose the Python version you wish to install from https://www.python.org/downloads/source/ and note the path to the “Gzipped source tarball” you intend to use. I’m choosing 3.10.9, so in the terminal, I’ll enter wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz to download the file.
  5. Extract the file by entering tar -xf Python-3.10.9.tgz in the terminal.
  6. Enter the python directory by entering cd Python-3.10.9 in the terminal.
  7. Set the configuration by entering ./configure --enable-optimizations in the terminal.
  8. Enter nproc in the terminal to check the number of processors you have available. I have 4.
  9. Enter make -j 4 in the terminal, replace “4” with the number of processors you have. This step will take a while.
  10. Install Python by entering sudo make install in the terminal.
  11. Check that you were successful by entering Python3.10 --version in the terminal. If it prints back the version you intended to install then all is well.

Congratulations. Your Google Cloud Workstation is now ready for you to begin developing with Python.

--

--

Benjamin Engen
Google Cloud - Community

Senior Analytics Engineer @ The Zebra