arrow_back

Google Cloud Fundamentals: Getting Started with App Engine

Sign in Join
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Google Cloud Fundamentals: Getting Started with App Engine

Lab 20 minutes universal_currency_alt 5 Credits show_chart Introductory
info This lab may incorporate AI tools to support your learning.
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Overview

In this lab, you create and deploy a simple App Engine application using a virtual environment in the Google Cloud Shell.

Objectives

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

  • Initialize App Engine.
  • Preview an App Engine application running locally in Cloud Shell.
  • Deploy an App Engine application, so that others can reach it.
  • Disable an App Engine application, when you no longer want it to be visible.

Set up your lab environment

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Sign in to Qwiklabs using an incognito window.

  2. Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time.
    There is no pause feature. You can restart if needed, but you have to start at the beginning.

  3. When ready, click Start lab.

  4. Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.

  5. Click Open Google Console.

  6. Click Use another account and copy/paste credentials for this lab into the prompts.
    If you use other credentials, you'll receive errors or incur charges.

  7. Accept the terms and skip the recovery resource page.

Activate Google Cloud Shell

Google 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.

Google Cloud Shell provides command-line access to your Google Cloud resources.

  1. In Cloud console, on the top right toolbar, click the Open Cloud Shell button.

    Highlighted Cloud Shell icon

  2. 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:

Project ID highlighted in the 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

Output:

Credentialed accounts: - @.com (active)

Example output:

Credentialed accounts: - google1623327_student@qwiklabs.net
  • You can list the project ID with this command:
gcloud config list project

Output:

[core] project =

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: Full documentation of gcloud is available in the gcloud CLI overview guide .

Task 1. Initialize App Engine

  1. Initialize your App Engine app with your project and choose its region:

    gcloud app create --project=$DEVSHELL_PROJECT_ID Note: When prompted, select the region where you want your App Engine application located.
  2. Clone the source code repository for a sample application in the hello_world directory:

    git clone https://github.com/GoogleCloudPlatform/python-docs-samples
  3. Navigate to the source directory:

    cd python-docs-samples/appengine/standard_python3/hello_world

Task 2. Run Hello World application locally

In this task, you run the Hello World application in a local, virtual environment in Cloud Shell.

Ensure that you are at the Cloud Shell command prompt.

  1. Create a Dockerfile

    touch Dockerfile
  2. Edit the Dockerfile [hint: nano Dockerfile] to contain the following content.

    FROM python:3.8 WORKDIR /app COPY . . RUN pip install gunicorn RUN pip install -r requirements.txt ENV PORT=8080 CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 main:app
Note: The Dockerfile will be used to create a local image.
  1. Build a container image to run a Python virtual environment.

    docker build -t test-python .
  2. Run the application:

    docker run --rm -p 8080:8080 test-python
  3. In Cloud Shell, click Web preview (Web Preview icon) > Preview on port 8080 to preview the application.

Note: To access the Web preview icon, you may need to collapse the Navigation menu.

Result:

Web preview show Hello World

  1. To end the test, return to Cloud Shell and press Ctrl+C to abort the deployed service.

  2. Using the Cloud Console, verify that the app is not deployed. In the Cloud Console, on the Navigation menu (Navigation menu icon), click App Engine > Dashboard.

Note: Notice that no resources are deployed.

Task 3. Deploy and run Hello World on App Engine

To deploy your application to the App Engine Standard environment:

  1. Navigate to the source directory:

    cd ~/python-docs-samples/appengine/standard_python3/hello_world
  2. Deploy your Hello World application.

    gcloud app deploy
Note: If prompted "Do you want to continue (Y/n)?", press Y and then Enter.

This app deploy command uses the app.yaml file to identify project configuration.

Note: If you get a Gaia propagation related error message, re-run the gcloud app deploy command.
  1. Launch your browser to view the app at http://YOUR_PROJECT_ID.appspot.com

    gcloud app browse

Copy and paste the URL into a new browser window.

Result:

Web preview showing Hello World

Congratulations! You created your first application using App Engine.

Click Check my progress to verify the objective. Deploy the Hello World application to App Engine

Task 4. Disable the application

App Engine offers no option to Undeploy an application. After an application is deployed, it remains deployed, although you could instead replace the application with a simple page that says something like "not in service."

However, you can disable the application, which causes it to no longer be accessible to users.

  1. In the Cloud Console, on the Navigation menu (Navigation menu icon), click App Engine > Settings.

  2. Click Disable application.

  3. Read the dialog message. Enter the App ID and click DISABLE.

If you refresh the browser window you used to view the application site, you'll get a 404 error.

Congratulations!

You created your first application using App Engine!

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

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.

This content is not currently available

We will notify you via email, when it becomes available

Great!

We will contact you via email, if it becomes available