
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Deploy an application to App Engine
/ 50
Create an App Engine latency alert
/ 50
In this lab, you deploy an application to App Engine and then create alerting policies to notify you if the application is not accessible or is generating errors.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
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:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
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.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
After you complete the initial sign-in steps, the project dashboard appears.
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.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
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:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
Run the following commands to update the python environment
Clone the Google Training Data Analyst from GitHub into your Cloud Shell environment. The repo contains a simple application which is perfect for the requirements in this exercise.
Once the cloning completes, change to the deploying-apps-to-gcp
folder in the repository that contains our sample app:
Open the main.py
file in the Cloud Shell editor. If prompted click Open in a new window. Take a moment to explore the basic "Hello GCP" Python Flask application.
Close the editor and switch back to the Cloud Shell terminal. Click Open terminal at the top right to open the Terminal window. To test the program, load all of the Python application dependencies and then start the app.
To see the program running, click the Web Preview button in the toolbar of Cloud Shell, and then select Preview on port 8080.
The program should open a new browser tab and display the Hello GCP
message.
Now that we know the application works, let's deploy it to the App Engine.
Switch to (or reopen) the Cloud Shell code editor. Expand the training-data-analyst/courses/design-process/deploying-apps-to-gcp
folder in the explorer tree on the left.
From the File menu, select New File and name the file app.yaml.
Paste the following into the file you just created:
To make sure the file is saved, select File > Save.
Every project needs to first create an App Engine application before it can be used. This is done just once per project using the console, or the gcloud app create
command. Either way, you need to specify the region where you want the app to be created.
Execute the following command in your Cloud Shell terminal. You may have to Authorize Cloud Shell to make such a change:
Deploy the basic application to App Engine. The following command looks in the current directory for the application. It sees the app.yaml file declaring it a Python application and it assumes the rest of the folder contains the application itself, with a starting point in main.py. It loads the dependencies, packages the application, and deploys into the App Engine as a Service.
Wait for the application to finish deploying.
In the Google Cloud console window, in the Navigation menu (), click View all products > Serverless > App Engine > Dashboard.
In the upper right of the dashboard, you see a link to your application similar to what is shown below.
https://project-id.wl.r.appspot.com
. Click the link to test your newly deployed app. It should function exactly like it did when we ran it in Cloud Shell.
Click refresh a number of times so Google Cloud can gather some sample data.
Click Check my progress to verify the objective.
Switch back to the Console and on the left side under App Engine
, click the Versions link.
Select Logs from the Diagnose
column.
Now that we have the application running, let's create an alert to watch for unusually high latency. To start, let's explore our application's current latency.
In the Google Cloud console, in the Navigation menu, click View all products, Observability > Monitoring > Metrics explorer.
Click on Select a metric drop-down and uncheck the Active option.
Set the Metric
to GAE Application > Http > Response latency. Click Apply. Make sure the metric is an App Engine metric, and not an uptime check metric. Because we don't currently have an uptime check, the second option won't work.
In the Aggregation field click on the dropdown and select 99th percentile.
Take a moment and examine the chart.
We don't have a lot of data but we should have enough to display a chart line showing us the average time it took our application to return a response to the fastest 99% of requests, cutting off 1% of anomalies.
Our application is performing as expected now. There may have been a few slow responses when the application was first launched, but on average, you should be seeing response times under 200ms.
Let's create an alert to notify us if we have response times over 5s for more than a minute.
In the Google Cloud console, on the Navigation menu (), click View all products > Observability > Monitoring > Alerting.
At the top, click Edit Notification Channels and scroll to the Email section. Use Add New to add your email address as a valid notification channel. For Display name
, choose any name and then click Save.
Switch back to the main Alerting page and click Create policy.
Click Select a metric and uncheck the Active option to display the same metric explorer page. Once again, set the Metric
to GAE Application > Http > Response latency. Click Apply. Set rolling window to 1 min
and then click Next.
You'll notice the new Configuration
section that's been added to the standard Metrics explorer window in the lower left.
Set up a condition so that if Any time series violates the Threshold position
is Above threshold and Threshold value
to 8000ms, it should trigger an alert.
Set the condition name
to Response latency [MEAN] for 99th% over 8s.
Take a moment to examine the alert's chart. It's the same chart we created earlier with the Metrics explorer, but this time there should be an alert line drawn at 8s.
Click Next.
For Notifications and name
, expand the Notification Channel
and check yourself, click OK (the notification channel you created earlier in this section).
Name the alert Hello too slow and click Next. Review alert and click Create Policy.
Update the application code to add a delay. Return to the Cloud Shell code editor. Expand the training-data-analyst/courses/design-process/deploying-apps-to-gcp folder in the explorer tree on the left.
Click main.py
to open it in the editor. Near the top at line 2, add the following imports statements (some will be used later in the exercise):
Replace the current main()
function with the one below. This new version adds a sleep command which pauses the code for 10s in the middle of each request. This will be well over the threshold.
Now re-deploy your application by rerunning:
Wait for the command to finish the re-deployment.
After the command completes, return to Serverless > App Engine > Dashboard and make sure the link works.
To generate some consistent load, in Cloud Shell, enter the following command:
Wait and after a few minutes (typically about 5), you should receive an email notifying you of the alert. When you do, switch back to the Cloud Shell terminal and use CTRL+C to stop the load tester loop.
In the Google Cloud console, on the Navigation menu (), click View all products > Observability > Monitoring > Alerting.
Notice the firing alert and how it created an incident.
Click the incident to view details.
Investigate the details page, scroll to the top and select Acknowledge incident.
Switch back to the main Alerting page and notice the changes.
Click Check my progress to verify the objective.
The Alerting CLI (and API) can be very effective when applying alerting policies with code or scripts.
Return to the Cloud Shell code editor. Select the training-data-analyst/courses/design-process/deploying-apps-to-gcp folder in the explorer tree on the left.
From the File menu, select New File and name the file app-engine-error-percent-policy.json.
Create an alerting policy which divides the number of 500 errors by the total number of responses, then triggers when the 500 errors exceed 1 percent. Paste the following into the file you just created:
Save your file. Make sure you are in the correct folder and that your alerting policy was saved there.
Deploy the alerting policy with the following command:
In the Google Cloud console, on the Navigation menu (), click Observability > Monitoring > Alerting. In the Policies section, you should see the alerting policy you just deployed.
Click your HTTP error… policy to see its details. Edit the notification channel so you receive an email when the alert fires.
Deploy the App Engine app with a random error to test this policy. Return to the Cloud Shell code editor. Expand the training-data-analyst/courses/design-process/deploying-apps-to-gcp folder in the explorer tree on the left.
Open the main.py
file in the Cloud Shell editor.
Replace the current main()
function with the one below. This new function removes our sleep command and uses the random number generator to return a 500 error about 2% of the time. This should be enough to cause your HTTP error count policy to trigger.
Redeploy your application with the following command:
Wait for the command to finish the redeployment.
After the command completes, return to the App Engine > Dashboard and make sure the link works.
In Cloud Shell, rerun the load generator command from earlier:
In Cloud Shell, you should see an error appear randomly about 2% of the time. Leave the command running.
In the Google Cloud console, on the Navigation menu (), click Observability > Monitoring > Alerting, and wait another few minutes. You should see an alerting incident fire. You should also get an email. This won’t happen immediately, you have to be patient.
Once you get the email and see the incident fire, go back to Cloud Shell and press CTRL+C to stop the requests.
If you wait a couple more minutes, you see the incident resolve itself and get another email.
To make sure you don’t get any emails after the project is deleted, delete your notification channels. Click the HTTP error count… policy to see its details. Click the Edit link, expand the Notification Channel and uncheck yourself. Toggle off Use notification channel
. Save your changes and then Delete the policy.
Repeat the previous step to your Uptime check alerting policy.
In this exercise, you used the Google Cloud Console and CLI to create and test alerting policies. Good job!
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:
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 2025 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
One lab at a time
Confirm to end all existing labs and start this one