Google Cloud Shell is a browser-based command line tool to access Google Cloud Platform resources. Cloud Shell makes it really easy to manage your Cloud Platform Console projects and resources without having to install the Google Cloud SDK and other tools on your system. With Cloud Shell, the Cloud SDK gcloud command and tools you need to build a Java application, such as the JVM, Maven, and Gradle.

In this lab, you will learn about how to build and launch an Java web-application created with Spring Boot from Google Cloud Shell — without ever leaving the browser.

This tutorial uses the sample code from the Spring Boot Getting Started guide.

What you'll learn

What you'll need

How will you use use this tutorial?

Read it through only Read it and complete the exercises

How would you rate your experience with building HTML/CSS web apps?

Novice Intermediate Proficient

How would you rate your experience with using Google Cloud Platform services?

Novice Intermediate Proficient

Codelab-at-a-conference setup

The instructor will be sharing with you temporary accounts with existing projects that are already setup so you do not need to worry about enabling billing or any cost associated with running this codelab. Note that all these accounts will be disabled soon after the codelab is over.

Once you have received a temporary username / password to login from the instructor, log into Google Cloud Console:

Here's what you should see once logged in :

Note the project ID you were assigned ( "codelab-test003" in the screenshot above). It will be referred to later in this codelab as PROJECT_ID.

Google Cloud Shell

While Google Cloud and Kubernetes can be operated remotely from your laptop, in this codelab we will be using Google Cloud Shell, a command line environment running in the Cloud.

This Debian-based virtual machine is loaded with all the development tools you'll need. It offers a persistent 5GB home directory, and runs on the Google Cloud, greatly enhancing network performance and authentication. This means that all you will need for this codelab is a browser (yes, it works on a Chromebook).

To activate Google Cloud Shell, from the developer console simply click the button on the top right-hand side (it should only take a few moments to provision and connect to the environment):


Click the "Start Cloud Shell" button:

Screen Shot 2017-06-14 at 10.13.43 PM.png

Once connected to the cloud shell, you should see that you are already authenticated and that the project is already set to your PROJECT_ID :

gcloud auth list

Command output

Credentialed accounts:
 - <myaccount>@<mydomain>.com (active)
gcloud config list project

Command output

project = <PROJECT_ID>

Cloud Shell also sets some environment variables by default which may be useful as you run future commands.


Command output


If for some reason the project is not set, simply issue the following command :

gcloud config set project <PROJECT_ID>

Looking for your PROJECT_ID? Check out what ID you used in the setup steps or look it up in the console dashboard:


IMPORTANT: Finally, set the default zone and project configuration:

gcloud config set compute/zone us-central1-f

You can choose a variety of different zones. Learn more in the Regions & Zones documentation.

Start Cloud Shell

Navigate to the the Google Cloud Console from another browser tab/window, to Use the login credential given to you by the lab proctor.

You will do all of the work from the Google Cloud Shell, a command line environment running in the Cloud. This Debian-based virtual machine is loaded with all the development tools you'll need (gcloud, git and others) and offers a persistent 5GB home directory. Open the Google Cloud Shell by clicking on the icon on the top right of the screen:


Once the Spring Boot CLI is installed, you can initialize and bootstrap a new Helloworld web application:

$ curl \
  -d dependencies=web -d baseDir=helloworld | tar -xzvf -

This will create a new directory with a new Maven project, along with Maven's pom.xml, a Maven wrapper, as well as an application entrypoint.

Open the Web Code Editor by clicking Launch code editor from the Cloud Shell menu.

Once the code editor is open, find the file helloworld/src/main/java/com/example/demo/

Once the code is open, create a new RESTful controller to respond "Hello". In the file, add a new Helloworld class definition in addition to the current one:


package com.example;


// Add the import
import org.springframework.web.bind.annotation.*;

public class DemoApplication {

// Add the controller
class Helloworld {
        public String greet() {
                return "Hello!";

Don't forget to save the file!

You can start the Spring Boot application normally with the Spring Boot plugin:

$ cd $HOME/helloworld
$ ./mvnw -DskipTests spring-boot:run

Once the application started, click on the Web Preview in the Cloud Shell toolbar and choose preview on port 8080.

A tab in your browser opens and connects to the server you just started.

You learned how to build and launch a new Java web-based application directly from Cloud Shell.

Learn More


This work is licensed under a Creative Commons Attribution 2.0 Generic License.