Deploying Your App on Google Cloud: A Hands-On Guide with App Engine

NitinNitin
4 min read

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 at the top of the Google Cloud console.

gcloud config set compute/region us-central1

Click ‘authorize’

![A screen shot of a computer

Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXezHUUsyBiaHNZ0cp0hQ6-Ja_T510khVi3mlvML37m-Jw94pgg37HsXmznLifHnWm1BrtkLFkwy0pZBbrBPUhwc3W53qITFelNKW3KZ6alboiKBzDnDMauszSSuc64lfykGXrScl0qXf-M0NLpixU4mRrS67q3I7YOQrxTOYiqvATDeTNbVRU?key=h8e2-XDxbp_MLGj2QmA0g align="left")

Enable Google App Engine Admin API

The App Engine Admin API enables developers to provision and manage their App Engine Applications.

  1. In the left Navigation menu, click APIs & Services > Library.

  2. Type "App Engine Admin API" in the search box.

  3. Click the App Engine Admin API card.

  4. Click Enable. If there is no prompt to enable the API, then it is already enabled and no action is needed.

Download the Hello World app

There is a simple Hello World app for Python you can use to quickly get a feel for deploying an app to Google Cloud. Follow these steps to download Hello World to your Google Cloud instance.

  1. Enter the following command to copy the Hello World sample app repository to your Google Cloud instance:

git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

  1. Go to the directory that contains the sample code:

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

  1. Setup python environment:

sudo apt install python3 -y

sudo apt install python3.11-venv

python3 -m venv create myvenv

source myvenv/bin/activate

Test the application

Test the application using the Google Cloud development server (dev_appserver.py), which is included with the preinstalled App Engine SDK.

  1. From within your helloworld directory where the app's app.yaml configuration file is located, start the Google Cloud development server with the following command:

dev_appserver.py app.yaml

The development server is now running and listening for requests on port 8080.

  1. View the results by clicking the Web preview () > Preview on port 8080.

![A screenshot of a computer

Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXf7GionwwOTngJmmzD2pCCaQNm1CUn1NeQ2LqAwe61c56OHgysx2gOLdrphOzU9BLiehFKBdMODbG0SQ3tcyT1ZWYeVU_TpUMpcFHxsRsRJF0kDHYpoN8ej7VOrDpLTQ-U2FM6C2bqwtU7FIzwJD3gt7otFf38Wr3DzVnOu3vG4TZ4zGjulhI?key=h8e2-XDxbp_MLGj2QmA0g align="left")

You'll see this in a new browser window:

Make a change

You can leave the development server running while you develop your application. The development server watches for changes in your source files and reloads them if necessary.

Let's try it. Leave the development server running. We'll open another command line window, then edit main.py to change "Hello World!" to "Hello, Cruel World!".

  1. Click the (+) next to your Cloud Shell tab to open a new command line session.

+ button

  1. Enter this command to go to the directory that contains the sample code:

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

  1. Enter the following to open main.py in nano to edit the content:

nano main.py

  1. Change "Hello World!" to "Hello THE BEST World!".

  1. Save the file with CTRL-S and exit with CTRL-X.

  2. Reload the Hello World! Browser or click the Web Preview () > Preview on port 8080 to see the results.

![A close up of a number

Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcS-_JV8t1q10V-FbagdccE9NN4PAIE81zIUcG3E5fYz75omq6kLz8CqZKWM4D1yQ5MuFV5URfGkWHniECuHXSvCQbSy84T3Bn8VjPh-ly1wjWlawTe3w1zfMs88zKrFZ5NDwHDS1oMEJ4awr0o_ot-CZ0rQwE33E7uxnt4jtCyZNv8SgctQ?key=h8e2-XDxbp_MLGj2QmA0g align="left")

Deploy your app

  1. To deploy your app to App Engine, run the following command from within the root directory of your application where the app.yaml file is located:

gcloud app deploy

  1. Enter the number that represents your region: us-central

  2. The App Engine application will then be created.

Example output:

Enter Y when prompted to confirm the details and begin the deployment of service.

Example output:

You can stream logs from the command line by running:

$ gcloud app logs tail -s default

To view your application in the web browser run:

$ gcloud app browse

Note: If you receive an error as "Unable to retrieve P4SA" while deploying the app, then re-run the above command.

View your application

  • To launch your browser enter the following command, then click on the link it provides:

gcloud app browse

Example output (note that your link will be different):

Browsed app ☺

![A screenshot of a computer

Description automatically generated](https://lh7-rt.googleusercontent.com/docsz/AD4nXf9SYS-M0Anm2EdDNqRBXSTw1tBkHCbBA-pJ9ea9D0sRY97yOoAWdwCKHFSif3Q-1k5p3zlPsaKvaGZd8SjO31QT5uIVDKjZ1QmDyRwTRaURx2RWDJlJJ58ZpobQMGES9uoKZdbYs6JjxDLvhPEY1YqjtzKoHz-qHxG5TMMc4HoKfDFQGhFIMI?key=h8e2-XDxbp_MLGj2QmA0g align="left")

Your application is deployed, and you can read the short message in your browser.

Deploying your app on Google Cloud using App Engine is a straightforward process that offers robust tools and services to ensure a smooth deployment experience. By following the steps outlined in this guide, you can activate Cloud Shell, enable necessary APIs, download and test a sample application, make changes, and finally deploy your app. This hands-on approach not only helps you understand the deployment process but also equips you with the skills to manage and scale your applications effectively on Google Cloud. Whether you're a beginner or an experienced developer, Google Cloud's App Engine provides a reliable and scalable platform for your applications.

0
Subscribe to my newsletter

Read articles from Nitin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nitin
Nitin

A Seasoned gate keeper for software quality (Manual / Automation (Web + Mobile native + API) / Performance test) with 13 years of experience, An automation🤖 lover and a continuous📚 learner. A test automation geek and a DevOps engineer using and exploring cloud☁️. Looking for opportunities in Cloud DevOps for mutual growth. (Working remotely since last 5 years with teams in Europe / USA and Canada)