arrow_back

APIs Explorer: App Engine

Join Sign in

APIs Explorer: App Engine

45 minutes 1 Credit

GSP422

Google Cloud self-paced labs logo

Overview

Google APIs Explorer is a tool that lets you try out various Google APIs interactively. With the APIs Explorer, you can:

  • Browse quickly through available APIs and versions.
  • See methods available for each API and what parameters they support along with inline documentation.
  • Execute requests for any method and see responses in real-time.
  • Make authenticated and authorized API calls.
  • Search across all services, methods, and your recent requests to quickly find what you are looking for.

App Engine lets you deploy applications on a fully managed platform. You can scale your applications seamlessly without having to worry about managing the underlying infrastructure. With zero server management and zero configuration deployments, developers can focus only on building great applications without the management overhead.

In this lab you will deploy a simple hello world application to App Engine and make updates to its configuration using the App Engine Admin API through the APIs Explorer tool.

Objectives

In this lab, you will:

  • Build an App Engine application with the APIs Explorer tool.
  • Deploy an App Engine instance from the hello world sample code.
  • Configure App Engine firewall rules with the APIs Explorer tool.
  • Make changes to your code base and create a new version of your application with the APIs Explorer tool.

Prerequisites

This is a fundamental level lab. You should be familiar with the basic functioning and architecture of APIs. Experience with Google Cloud Shell and command-line interface tools is recommended.

Familiarity with the APIs Explorer tool is also recommended. At a minimum, take the following labs before attempting this one:

If you are unfamiliar with App Engine, the App Engine: Qwik Start - Python lab has valuable information that will orient you with the content of this lab. Once you're ready, scroll down and follow the steps below to set up your lab environment.

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.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

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 the Lab Details panel with the following:

    • The Open Google Console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

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

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.

  4. Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  5. 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.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left. Navigation menu icon

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.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

  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. The output contains a line that declares the PROJECT_ID for this session:

Your Cloud Platform project in this session is set to YOUR_PROJECT_ID

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

  1. (Optional) You can list the active account name with this command:

gcloud auth list

Output:

ACTIVE: * ACCOUNT: student-01-xxxxxxxxxxxx@qwiklabs.net To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:

gcloud config list project

Output:

[core] project = <project_ID>

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Build an App Engine application with apps.create

You will now build an App Engine application with one of the methods found in the APIs Explorer.

  1. To access the App Engine APIs Explorer tool, open up the navigation menu and select APIs & Services > Library.

  2. In the search bar, enter in App Engine and select the App Engine Admin API from the results list. Make sure that API is enabled, if not click Enable.

  3. Now that you have verified the API's enablement, open the Method: apps.create reference. This will take you to the apps create method.

  4. Under Try this API in the right panel, click in the Request body field and add:

  • The ID property. Set it's value to your Project ID.

  • The locationId property. Set its value to us-west2. This required field tells Google Cloud where your App Engine resources will live.

  1. Make sure that there are no trailing spaces in any of the fields. Also, that Google OAuth 2.0 and API key checkboxes are selected under Credentials section.

The Credentials section with both checkboxes checked.

Note: To view Credentials FAQs, click on question mark icon next to Credentials title.
  1. Click the EXECUTE button.

  2. Select the student account you started the lab with.

  3. On the next screen, click Allow to give APIs Explorer access.

Your response should resemble the following:

{ "name": "apps/qwiklabs-gcp-da84962e277c92a7/operations/193f576c-8791-4638-920e-b1ccb6305ae1", "metadata": { "@type": "type.googleapis.com/google.appengine.v1.OperationMetadataV1", "method": "google.appengine.v1.Applications.CreateApplication", "insertTime": "2019-10-16T12:37:36.743Z", "user": "gcpstaging92860_student@qwiklabs.net", "target": "apps/qwiklabs-gcp-da84962e277c92a7" } }

You have successfully built an App Engine application for a Google Cloud project.

Task 2. Get application information with apps.get

Next you'll retrieve some information on your App Engine application to ensure that it has been properly created.

  1. From the left All APIs & Reference section navigate to REST API > v1 > apps > get. Or you can use this direct link to apps.get method.

  2. For the appsId field, enter your <PROJECT_ID> found in the Connection Details section of the lab.

  3. Make sure that Google OAuth 2.0 and API key checkboxes are selected under Credentials section.

The Credentials section

  1. Click the EXECUTE button. You may need to select the student account and click Allow again.

Your response should resemble the following:

{ "name": "apps/qwiklabs-gcp-da84962e277c92a7", "id": "qwiklabs-gcp-da84962e277c92a7", "authDomain": "gmail.com", "locationId": "us-west2", "codeBucket": "staging.qwiklabs-gcp-da84962e277c92a7.appspot.com", "servingStatus": "SERVING", "defaultHostname": "qwiklabs-gcp-da84962e277c92a7.appspot.com", "defaultBucket": "qwiklabs-gcp-da84962e277c92a7.appspot.com", "gcrDomain": "us.gcr.io", "featureSettings": { "splitHealthChecks": true, "useContainerOptimizedOs": true } }

This method works as a sanity check and offers you useful information about your App Engine application, such as its default hostname, location, and serving status.

Task 3. Download the starter code

Before you deploy an App Engine application, you will need to download some starter code so you have something to work with.

  1. Return to the Cloud Console and in Cloud Shell run the following command to clone a repository that contains the codebase for a simple hello world application:

git clone https://github.com/GoogleCloudPlatform/python-docs-samples
  1. Now change your current working directory:

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

The hello_world folder contains a simple Python application that uses the Flask web framework. This Python app responds to a request with an HTTP header and the message "Hello World!"

Task 4. Deploy your App Engine application

  1. For this step, remain in your Cloud Shell session. Run the following command to set your Project ID as an environment variable, replacing [YOUR_PROJECT_ID] with your Project ID:

export PROJECT_ID=[YOUR_PROJECT_ID]
  1. Now run the following gcloud command to deploy your hello world application:

gcloud app deploy app.yaml --project $PROJECT_ID
  1. When prompted with the following, enter in Y:
Do you want to continue (Y/n)?

The deployment will take a couple minutes to complete. Once it has finished, you should receive a similar output:

File upload done. Updating service [default]...done. Setting traffic split for service [default]...done. Deployed service [default] to [https://qwiklabs-gcp-b5d5fa242d334941.appspot.com]
  1. Copy the deployed service link that resembles https://qwiklabs-gcp-b5d5fa242d334941.appspot.com and paste it in a new tab. This will open the hello world application. Your page should resemble the following:

A web page displaying the text 'Hello World!'

Now that your application is deployed, you will make some changes to your App Engine configuration with the APIs Explorer.

Keep the Hello World! page open.

Test completed task

Click Check my progress to verify your performed task. If you have successfully deployed an app engine application, you will see an assessment score.

Deploy an app engine application

Task 5. Configure ingress firewall rules with apps.firewall.ingressRules

You will now create, list, and delete firewall rules that prescribe access to your hello world application.

Create an ingress firewall rule

  1. From the APIs & Reference section navigate to REST API > v1 > apps.firewall.ingressRules > create . Or, you can use this direct link to apps.firewall.ingressRules.create method.

  2. For the parent field, enter apps/<PROJECT_ID>. Make sure to replace <PROJECT_ID> with your Project ID.

  3. For the appsId field, enter your Project ID.

  4. Now click on the Request body and add:

  • The sourceRange property. Set it's value to *.
  • The action property. Set its value to DENY.
  • The priority property and set its value to 1.

Your method should resemble the following:

The method displayed in the Request body field

  1. Verify that your fields have no trailing spaces. Also, that Google OAuth 2.0 and API key checkboxes are selected under Credentials section.

The Credentials section

  1. Click the EXECUTE button. Your response should resemble the following:
{ "priority": 1, "action": "DENY", "sourceRange": "*" }

This firewall rule rejects all requests to your hello world application.

  1. To see it in action, Refresh your hello world page in your browser. You should now see that access is now forbidden: The Google 403 error displayed.

  2. Return to the APIs Explorer page for the next step.

List ingress firewall rules

  1. From the left All APIs & Reference section navigate to REST API > v1 > apps.firewall.ingressRules > list Or you can use this direct link to apps.firewall.ingressRules.list method.

  2. For the appsId field, enter your Project ID.

The highlighted project ID in the appsId text field

  1. Verify that the appsId field has no trailing spaces. Also, that Google OAuth 2.0 and API key checkboxes are selected under Credentials section.

The Credentials section

  1. Click the EXECUTE button.

Your response should resemble the following:

{ "ingressRules": [ { "priority": 1, "action": "DENY", "sourceRange": "*" }, { "priority": 2147483647, "action": "ALLOW", "sourceRange": "*", "description": "The default action." } ] }

You now see the two firewall rules: one that allows traffic and another that denies traffic to your application. Note the priority values for each ingress rule — these act as firewall rule IDs as well.

Delete an ingress firewall rule

  1. From the left All APIs & Reference section navigate to REST API > v1 > apps.firewall.ingressRules > delete Or you can use this direct link to apps.firewall.ingressRules.delete method.

  2. For the appsId field, enter your Project ID. For the ingressRulesId field, enter 1. Your method should resemble the following:

The method displayed in the Request parameters section

  1. Verify that your fields have no trailing spaces. Also, that Google OAuth 2.0 and API key checkboxes are selected under Credentials section.

The Credentials section

  1. Click the EXECUTE button.

Your response should resemble the following:

{}
  1. Now refresh your hello world page in your browser. You should now see that access been restored:

A web page with the text 'Hello World!'

Now that you've gotten practice with ingress firewall rule configuration, take it to the next level by creating and deploying new versions of our application.

Task 6. Update your application files

Now make a small change to your application's source code.

  1. For this step, return to the Cloud Shell. You should still be in the hello_world directory. If not, run the following command:

cd ~/python-docs-samples/appengine/standard_python3/hello_world
  1. Now open the main.py file with the nano text editor:

nano main.py
  1. Scroll down to the hello function and edit it so it says "Goodbye world!" instead:
@app.route('/') def hello(): """Return a friendly HTTP greeting.""" return 'Goodbye World!'
  1. Press CNTRL +x then Y > ENTER to save your changes and exit the nano editor.

Task 7. Create a new version of your application with apps.services.versions.create

You will now create a new version of your application that uses your updated "Goodbye world!" codebase.

  1. In the Cloud Console, from the Navigation menu select Cloud Storage > Browser. You should see a list of buckets that resemble the following:

The Browser page displaying a list of buckets

  1. Copy the staging.qwiklabs-gcp-xxxx.appspot.com bucket name and save it.

  2. Now click on that bucket to view the files it contains.

  3. Copy the name of the application/json file and save it.

The name of the application/json file highlighted on the Objects tabbed page

You now have the information needed to create a new version of your hello world application.

  1. Return to the APIs Explorer for the next step.

  2. From the left All APIs & Reference section navigate to REST API > v1 > apps.services.versions > create. Or you can use this direct link to apps.services.versions.create method.

  3. For the appsId field, enter your Project ID. For the servicesId field, enter default.

  4. Now click in the request body and add:

  • The id property. Set it's value to v1.
  • The runtime property and set its value to python37.
  • Add the entrypoint property—inside, then add the shell property and keep it's value empty.

Your method should now resemble the following:

The method displayed in the Request parameters section

  1. Now add the deployment property.

    • Inside deployment, add a new property files and click the add link that comes underneath it. Give it the name latest.
    • Add the sourceUrl property in latest and set it to the following, replacing <YOUR_BUCKET_NAME> with the name of the staging Cloud Storage bucket and <YOUR_JSON_FILE_NAME> with the name of the JSON file you copied over:
https://storage.googleapis.com/<YOUR_BUCKET_NAME>/<YOUR_JSON_FILE_NAME>

Your method should now resemble the following:

The method displayed in the Request body text field

  1. Make sure that Google OAuth 2.0 and API key checkboxes are selected under Credentials section.

The Credentials section

  1. Once that's filled out, click the EXECUTE button.

You should receive the following output:

{ "name": "apps/qwiklabs-gcp-da84962e277c92a7/operations/7ca371a7-3bf6-4215-871e-7f9aac815714", "metadata": { "@type": "type.googleapis.com/google.appengine.v1.OperationMetadataV1", "method": "google.appengine.v1.Versions.CreateVersion", "insertTime": "2019-10-16T14:39:19.231Z", "user": "gcpstaging92860_student@qwiklabs.net", "target": "apps/qwiklabs-gcp-da84962e277c92a7/services/default/versions/v1" } }

There were many fields to fill out, but that is where the APIs Explorer shines. Being able to visualize all the parameters and see how they relate to one another is critical in successfully calling API methods.

Task 8. Deploy the new version of your application

  1. Return to the Cloud Console for this step.

  2. Open the navigation menu and select App Engine > Versions.

You should see that there are now two versions of your application available:

The Versions page displaying two versions of the application

Note: If you don't see two versions, it's possible that your updates haven't propagated yet. Click the Refresh button in the top left corner until your page resembles the above screenshot.
  1. Return to your Cloud Shell session. You should still be in the hello_world directory. If not, run the following command:

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

You will now deploy the new version of your application.

  1. Run the following command to deploy the new version, with "Goodbye world!" as the message:

gcloud app deploy -v v1
  1. When prompted with the following, enter in Y:
Do you want to continue (Y/n)?

The deployment will take a couple minutes to complete.

Once it has finished, you should receive a similar output:

File upload done. Updating service [default]...done. Setting traffic split for service [default]...done. Deployed service [default] to [https://qwiklabs-gcp-b5d5fa242d334941.appspot.com]
  1. Now copy the link or refresh the application page in your browser. You should see the following:

A web page displaying the text 'Goodbye World!'

If you return to the Cloud Console and look at App Engine > Versions you will see that that v1 is being run:

The Service page displaying v1 with the Status set to Serving, and Traffic Alloctaion at 100 percent

You have successfully created a new version of an application with the APIs Explorer and deployed it in Cloud Shell.

Test completed task

Click Check my progress to verify your performed task. If you have successfully created a new version of your app, you will see an assessment score.

Create a new version of your app

Congratulations!

In this lab, you got hands-on practice with App Engine Admin API methods using the APIs Explorer. After building an App Engine application with the APIs Explorer tool, you deployed an instance from the hello world sample code. You then learned how to configure ingress firewall rules with the APIs Explorer tool. After making changes to the codebase, you used the APIs Explorer to create a new version of your application, which you deployed and successfully accessed. You are now ready to take more Exploring APIs labs.

Finish your quest

This self-paced lab is part of the Exploring APIs quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge 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 any quest that contains this lab and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.

Take your next lab

Be sure to check out the following labs for more practice with the APIs Explorer:

Next steps / Learn more

Google Cloud training and 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: September 28, 2022

Lab Last Tested: July 23, 2021

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.