Google App Engine applications are easy to create, easy to maintain, and easy to scale as your traffic and data storage needs change. With App Engine, there are no servers to maintain. You simply upload your application and it's ready to go.
App Engine applications automatically scale based on incoming traffic. load balancing, microservices, authorization, SQL and NoSQL databases, Memcache, traffic splitting, logging, search, versioning, roll out and roll backs, and security scanning are all supported natively and are highly customizable.
App Engine's environments, the Standard Environment and the Flexible environment, support a host of programming languages, including Java, Python, PHP, NodeJS, Go, etc.. The two environments give users maximum flexibility in how their application behaves since each environment has certain strengths. Read The App Engine Environments for more information.
In this codelab, you will learn how to to connect to computing resources hosted on Google Cloud Platform via the web. You will learn how to use Cloud Shell and the Cloud SDK gcloud command.
This tutorial uses the sample code from the Spring Boot Getting Started guide.
If you don't already have a Google Account (Gmail or Google Apps), you must create one. Sign-in to Google Cloud Platform console (console.cloud.google.com) and create a new project:
Remember the project ID, a unique name across all Google Cloud projects (the name above has already been taken and will not work for you, sorry!). It will be referred to later in this codelab as
Next, you'll need to enable billing in the Developers Console in order to use Google Cloud resources.
Running through this codelab shouldn't cost you more than a few dollars, but it could be more if you decide to use more resources or if you leave them running (see "cleanup" section at the end of this document).
New users of Google Cloud Platform are eligible for a $300 free trial.
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 (
kubectl and more), 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):
Once connected to the cloud shell, you should see that you are already authenticated and that the project is already set to your
$ gcloud auth list Credentialed accounts: - <myaccount>@<mydomain>.com (active)
$ gcloud config list project [core] project = <PROJECT_ID>
If for some reason the project is not set, simply issue the following command :
$ gcloud config set project <PROJECT_ID>
Looking for you
PROJECT_ID? Check out what ID you used in the setup steps or look it up in the console dashboard :
Navigate to the the Google Cloud Console from another browser tab/window, to https://console.cloud.google.com. 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 (
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:
Google Cloud Shell has both Java 7 and Java 8 installed. It uses Java 7 by default. Let's switch to use Java 8 instead. In the Cloud Shell, use
update-alternative command to change the default Java version (make sure you select the
java-8-openjdk option by typing "2"):
$ sudo update-alternatives --config javac There are 2 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac ... 1 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac ... 2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac ... Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode $ sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java ... 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java ... 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java ... Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
After Cloud Shell launches, you can use the command line to clone the example source code in the home directory:
$ git clone https://github.com/spring-guides/gs-spring-boot.git $ cd gs-spring-boot/complete
There are multiple ways to deploy a Java server application - either by using a Maven or Gradle plugin, or by deploying the
war package directory.
pom.xml to include a Google Cloud Platform plugin that simplifies the deployment process. You can use
emacs to edit the file.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" ...> ... <build> <plugins> ... <plugin> <groupId>com.google.appengine</groupId> <artifactId>gcloud-maven-plugin</artifactId> <version>18.104.22.168.v20160420</version> </plugin> </plugins> </build> </project>
You can start the Spring Boot application normally with the Spring Boot plugin:
$ mvn spring-boot:run
Once the application started, click on the Web Preview icon 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.
Deploy your application into App Engine environment, run
$ mvn gcloud:deploy
After the application is deployed, you can visit it by opening the URL
http://<project-id>.appspot.com in your web browser.
In this step, you set up a simple Spring Boot application and ran and deployed your application on App Engine.
You learned how to write your first App Engine web application!
This work is licensed under a Creative Commons Attribution 2.0 Generic License.