Google App Engine

Google App Engine Tutorial for Beginners

Learn Google App Engine step by step: create a project, deploy a small Python web app, read its logs, and use Cloud Storage from your app code.

On this page
  1. What Google App Engine is
  2. Before you start
  3. Step 1: Set up your project and App Engine app
  4. Step 2: Write a small Flask app
  5. Step 3: Configure app.yaml
  6. Step 4: Deploy and open the app
  7. Step 5: Read logs and manage versions
  8. Using Cloud Storage from App Engine
  9. Costs and cleanup
  10. Where to go next

What Google App Engine is

Google App Engine is a platform as a service (PaaS). You upload your application code, and Google runs it on its own infrastructure. Google manages the servers, the operating system patches, and most of the scaling, so you can spend your time on the code instead of the machines underneath it.

That places App Engine above infrastructure as a service (IaaS) such as Compute Engine, where you manage the operating system yourself. Google first previewed App Engine in 2008 and made it generally available in 2011. Google now recommends Cloud Run for many new serverless apps, but App Engine is still supported.

App Engine has two environments. The Standard environment runs your code in a sandbox on supported language runtimes and can scale to zero when idle. The Flexible environment runs your app in Docker containers on Compute Engine virtual machines and keeps at least one instance running. The Standard vs Flexible comparison explains the trade-offs.

Before you start

You need three things:

  • A Google Cloud account with billing enabled. New customers get a $300 credit valid for 90 days. The cost guide explains what stays free after the trial.
  • The Google Cloud CLI (gcloud) installed on your computer.
  • Python 3 installed locally, so you can test the app before you deploy it.

Step 1: Set up your project and App Engine app

Sign in and choose your project:

gcloud init

Then create the App Engine app for that project, using a region close to your users:

gcloud app create --region=us-central1

Treat the region as permanent. An App Engine app’s region cannot be changed later, so moving regions means creating a new project. The architecture guide explains how projects, services, versions, and instances fit together.

Step 2: Write a small Flask app

Create a folder named hello-gae with three files. First, main.py:

from flask import Flask

app = Flask(__name__)


@app.route("/")
def hello():
    return "Hello from Google App Engine!"


if __name__ == "__main__":
    # Local testing only. App Engine serves `app` with gunicorn.
    app.run(host="127.0.0.1", port=8080, debug=False)

App Engine looks for a WSGI object named app in main.py. Keep debug=False, because Flask’s debugger should never run on a public server. The Flask deployment guide covers project layout, static files, and troubleshooting in more depth.

Next, requirements.txt lists the packages App Engine installs during deployment:

Flask

In a real project, pin exact versions so the deployed app matches what you tested.

Step 3: Configure app.yaml

app.yaml tells App Engine which runtime to use and how to scale the app:

runtime: python313
instance_class: F1
automatic_scaling:
  max_instances: 2

Runtime names change over time, so check the supported runtimes list before you deploy. The max_instances setting caps how many instances can run, which is a simple way to limit cost while you learn.

Values in app.yaml are not secret. Anyone who can read the deployment configuration can see them, so store passwords and API keys in Secret Manager instead.

Step 4: Deploy and open the app

From the folder that contains app.yaml, run:

gcloud app deploy
gcloud app browse

gcloud app deploy uploads your code, builds it with Cloud Build, and starts a new version. gcloud app browse opens the app in your browser. Apps created after February 2020 use URLs that include the region ID, in the form PROJECT_ID.REGION_ID.r.appspot.com.

Each deployment creates a new version, and old versions stay in place until you remove them.

Step 5: Read logs and manage versions

To follow requests and errors as they arrive:

gcloud app logs tail -s default

To list the versions your app has:

gcloud app versions list

To send all traffic to one version, set its share to 1, which means 100 percent:

gcloud app services set-traffic default --splits=VERSION_ID=1

Traffic splitting also lets you send part of your traffic to a new version before you switch everything over.

Using Cloud Storage from App Engine

App Engine instances don’t have a persistent disk for your files. In the Standard environment, the only writable path is /tmp, which lives in memory and counts against the instance’s RAM. Files you want to keep belong in Cloud Storage.

Setting that up takes three steps.

  1. Add the client library to requirements.txt:

    Flask
    google-cloud-storage
  2. Give the App Engine default service account access to your bucket. The account is named PROJECT_ID@appspot.gserviceaccount.com. This command grants it access to objects in one bucket:

    gcloud storage buckets add-iam-policy-binding gs://your-bucket-name \
      --member="serviceAccount:PROJECT_ID@appspot.gserviceaccount.com" \
      --role="roles/storage.objectAdmin"

    Use the narrowest role that works for your app. objectAdmin is broad, so it suits a tutorial better than production.

  3. Use the client library in your code:

    from google.cloud import storage
    
    
    def save_greeting(text):
        client = storage.Client()
        bucket = client.bucket("your-bucket-name")
        blob = bucket.blob("greetings/latest.txt")
        blob.upload_from_string(text)

    Call save_greeting from a route in main.py, for example after a form submission.

App Engine may create a default bucket named after your project, but not every project gets one. If yours doesn’t have one, create a bucket yourself.

Whether Cloud Storage is worth paying for depends on how much data you store, how often you read and write it, and how much leaves Google’s network. Standard storage has an Always Free allowance of 5 GB per month in US regions, but limits can change, so check the current pricing page. For large downloads, serve files through signed URLs rather than passing them through your app’s instances.

Costs and cleanup

  • The Standard environment includes a daily free quota: 28 F-instance hours, 9 B-instance hours, and 1 GB of outbound traffic. The Flexible environment has no free quota.

  • Budgets send alerts but do not stop spending, so set one as soon as billing is enabled.

  • Old versions can keep serving traffic or adding cost. Delete versions you no longer need:

    gcloud app versions delete VERSION_ID --service=default
  • If the project was only for testing, deleting the project removes the App Engine app and its resources. The pricing guide explains where the charges come from.

Where to go next

Keep exploring

Guides from other topics

All topics →