App Dev - Deploying the Application into App Engine Flexible Environment - Java

Join Sign in

App Dev - Deploying the Application into App Engine Flexible Environment - Java

1 hour 1 Credit


Google Cloud selp-paced labs logo


An App Engine app is a single application resource with one or more services. Each service can be configured to use different runtimes and to operate with different performance settings. Within each service, you can deploy versions of that service, and each then runs within one or more instances, depending on how much traffic you configured it to handle. For more information, see an overview of App Engine.

App Engine uses either a Standard or Flexible environment. A standard environment runs instances in a sandbox, limiting available CPU options and disc access.

In contrast, a flexible environment runs your application in Docker containers on Compute Engine virtual machines (VMs), which have fewer restrictions. For example, you can use the programming language or library of your choice, write to disk, and even run multiple processes. You also have the choice of Compute Engine machine types for your instances. For more information about App Engine environments, see The App Engine Standard Environment and App Engine Flexible Environment.

In this lab, you deploy a quiz application into App Engine flexible environment, and leverage App Engine features like versions and traffic splitting.


In this lab, you learn how to perform the following tasks:

  • Create an app.yaml file to describe the App Engine flexible environment requirements for an application.
  • Deploy the quiz application into App Engine flexible environment.
  • Employ versions and traffic splitting to perform A/B testing of an application feature.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Chrome OS device, open an Incognito window to run this lab.

How to start your lab and sign in to the Google Cloud Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.

    Open Google Console

  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Sign in

    Tip: Open the tabs in separate windows, side-by-side.

  3. In the Sign in page, paste the username that you copied from the left panel. Then copy and paste the password.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Training credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).

  4. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Cloud Console opens in this tab.

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

In the Cloud Console, in the top right toolbar, click the Activate Cloud Shell button.

Cloud Shell icon

Click Continue.


It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:

Cloud Shell Terminal

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

You can list the active account name with this command:

gcloud auth list


ACTIVE: * ACCOUNT: To set the active account, run: $ gcloud config set account `ACCOUNT`

You can list the project ID with this command:

gcloud config list project


[core] project = <project_ID>

(Example output)

[core] project = qwiklabs-gcp-44776a13dea667a6

Preparing the Case Study Application

In this section, you access Cloud Shell, clone the git repository that contains the Quiz application, configure environment variables, and run the application.

Clone source code in Cloud Shell

Enter the following command to clone the repository for the lab.

git clone

Configure the case study application

Now change the working directory:

cd ~/training-data-analyst/courses/developingapps/java/appengine/start

You will have to make one small change to your executable file. Open by running the following command:


Now find the gcloud beta functions deploy command near the bottom of the file and remove the beta command. Ensure that line of code resembles the following:

gcloud functions deploy process-feedback --runtime nodejs8 --trigger-topic feedback --source ./function --stage-bucket $GCLOUD_BUCKET --entry-point subscribe

Now exit the nano editor with CTRL + X > Y > Enter.

Run the executable file by by running the following command:


When prompted with Allow unauthenticated invocations of new function [process-feedback]?, enter in Y.

NOTE: Please re-run the above command, if you get an error as (gcloud.functions.deploy) OperationError: code=3, message=Failed to retrieve function source code

Review the code

In this lab you view and edit files. You can use the shell editors that are installed on Cloud Shell, such as nano or vim, or use the Cloud Shell code editor. This lab uses the Cloud Shell code editor.

Launch the Cloud Shell Editor

In the Cloud Platform Console, click Open editor. This icon looks like a pencil.


If an error indicates that the code editor could not be loaded because third-party cookies are disabled, click Open in New Window and switch to the new tab.

Navigate to training-data-analyst/courses/developingapps/java/appengine/start.

Click Check my progress to verify the objective.

Preparing the Case Study Application

Preparing Application Code for App Engine Flexible Environment Deployment

In this section, you modify the configuration files for deployment of the quiz application frontend into App Engine flexible environment.

Create the app.yaml file for the frontend

In the Cloud Shell code editor, open src/main/appengine/app.yaml.

The following content describes the App Engine configuration. Copy and paste the content into app.yaml. Be sure you replace [GCLOUD_BUCKET] with the appropriate bucket name GCLOUD_PROJECT-media from your project.


runtime: java env: flex runtime_config: jdk: openjdk8 handlers: - url: /.* script: this field is required, but ignored manual_scaling: instances: 1 resources: cpu: 1 memory_gb: 3.75 disk_size_gb: 10 env_variables: GCLOUD_BUCKET: [GCLOUD_BUCKET]

Save the file.

Deploy the quiz application to App Engine flexible environment

Return to the Cloud Shell window. If the Cloud Shell is not visible, click Open Terminal.

In Cloud Shell, enter the following command to deploy the quiz application to App Engine flexible environment.

mvn clean compile appengine:deploy

It may take around 10 minutes to complete the deployment.

You'll see output similar to the following when the deployment is complete:

INFO\] ---------------------------------------------------------------- \[INFO\] BUILD SUCCESS \[INFO\] -------------------------------------------------------------- \[INFO\] Total time: 10:21 min \[INFO\] Finished at: 2018-05-23T19:28:50-04:00 \[INFO\] Final Memory: 37M/90M \[INFO\] --------------------------------------------------------------

In the Cloud Platform Console, on the Navigation menu > App Engine > Dashboard.


Click on the link to your application in the top-right corner of the App Engine Dashboard to see your application, the Quite Interesting Quiz.


Click Check my progress to verify the objective.

Deploy the frontend to App Engine Flex

Updating an App Engine Flexible Environment Application

In this section, you will modify the application code and then redeploy the application.

Update the quiz application

In the Cloud Shell code editor, open the src/main/resources/static/index.html file. Add several exclamation points to the top-level heading.


<!-- This is just a fragment, only add the exclamation points --> <div class="container"> <h1>Welcome to the Quite Interesting Quiz!!!!!</h1> <div class="jumbotron"> <p>Welcome to the Quite Interesting Quiz where you can create a question, take a test or review feedback</p> </div>

Click File > Save to save the file.

Deploy the updated application

In Cloud Shell, redeploy the App Engine application.

mvn clean compile appengine:deploy \ -Dapp.deploy.stopPreviousVersion=False \ -Dapp.deploy.promote=False

It may take around 10 minutes for the deployment to update.

In the Console, click Navigation menu > App Engine > Dashboard.

Click on the application URL in the top-right corner of the window. You should see that your application still displays the old title.

In the App Engine window, click Versions. You may need to refresh the page until you see two versions of the applications.


Click on both version links to see the new and old version of the quiz application.

New version (notice those exclamation points!):


Old version:


Enable the checkbox for both versions of the application, and click Split traffic.


Select the radio button to deliver versions randomly.

Configure the traffic split to deliver 50% of traffic to the old version, and 50% to the new version.


Click Save.

Return to the Dashboard, set Version to All versions and click the application link.


Open a new browser. If possible the browser should be a different type, for example Google Chrome to Internet Explorer. Copy the application link and paste it in the new browser.

Refresh the homepage a few times.

Click Check my progress to verify the objective.

Updating an App Engine Flexible Environment Application


You created app.yaml, a file that describes App Engine flexible environment requirements for an application. You also deployed the application and employed traffic splitting.

Finish your Quest

completion_badge_Application_Development_-_Java-135.png completion_badge_Cloud_Development-135.png

This lab is part of the Application Development - Java and Cloud Development Quests. A Quest is a series of related labs that form a learning path. Completing this Quest earns you the badge above, to recognize your achievement. You can make your badge (or badges) public and link to them in your online resume or social media account. Enroll in this Quest and get immediate completion credit if you've taken this lab. See other available Quests.

Next steps

Google Cloud Training & Certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual last updated October 18,2021
Lab last tested December 01, 2020

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.