Google App Engine (Standard) has undergone significant changes between the legacy and next generation platforms. To address this, we've created a set of codelabs (free, online, self-paced, hands-on tutorials) to show developers how to perform individual migrations they can apply to modernize their apps for the latest runtimes, with this repo managing the samples from those codelabs.
Codelabs begin with a "START" code base then walks developers through that migration step, resulting in a "FINISH" repo. If you made any mistakes along the way, you can always go back to START or compare your code with that in the FINISH folder to see the differences. Since another goal is to port to Python 3, some codelabs have a bonus section for that purpose.
NOTE: These migrations are only for those with Python 2 (2.7) App Engine apps.
- Python 3.x App Engine users: You're already on the next-gen platform, so there's no need for you to be here unless you help 2.x developers migrate.
- Python 2.5 App Engine developers: to revive apps on the original 2.5 runtime, deprecated in 2013 and shutdown in 2017, you must migrate from
db
tondb
before attempting these migrations.
- A Google account (G Suite accounts may require administrator approval)
- A Google Cloud (GCP) project with an active billing account
- Familiarity with operating system terminal/shell commands
- Familiarity with developing & deploying Python 2 apps to App Engine
- General skills in Python 2 and 3
App Engine is not a free service. While you may not have needed to enable billing in App Engine's early days, all applications now require an active billing account backed by a financial instrument (usually a credit card). Don't worry, App Engine (and other GCP products) still have an "Always Free" tier, and as long as you stay within those limits, you won't incur billing. Also check the App Engine pricing and quotas pages for more information.
In App Engine's early days, users wanted Google to make the platform more flexible for developers and make their apps more portable. As a result, the team made significant changes to its 2nd-generation service which launched in 2017. As a result, all previously built-in services have been removed, and users can either choose from new standalone Cloud products as replacements or best-of-breed replacements in the broader developer community. Summary:
- Legacy platform: Python 2 only, proprietary built-in services
- Next generation: Python 3 only, external services, flexible platform
The key issue is that developers looking to port their applications to Python 3 have two huge hurdles to overcome, migrating from Python 2 to 3 and migrating from built-in services to alternatives. On top of this, direct replacements are not available for all built-in services; alternatives come in 3 flavors:
- Direct replacement: Legacy services which matured into their own Cloud products (e.g., App Engine Datastore is now Cloud Datastore)
- Partial replacement: Some aspects of legacy services (e.g., Cloud Tasks supports App Engine push tasks; for pull tasks, Cloud Pub/Sub is recommended; use of Cloud MemoryStore with REDIS as an alternative for Memcache)
- No replacement: No direct replacement available, so third-party or other tools recommended (e.g., Search, Images, Users, Email)
These are the challenges developers are facing, so the purpose of this content is to make this process more smooth and prescriptive. Review the runtimes chart to see the legacy services and current migration recommendation. The migration guide overview has more information.
NOTE: App Engine (Flexible) is a next-gen service but is not within the scope of these tutorials. Developers who are curious can compare App Engine Standard vs. Flexible.
All codelabs begin with code in a START repo folder and end with code in a FINISH folder, implementing a single migration. Upon completion, users should confirm their code (for the most part) matches what's in the FINISH folder. The baseline migration sample app is a barebones Python 2.7 App Engine app that uses the webapp2
web framework plus the ndb
Datastore library. This is what's in the Module 0 repo folder (link below).
-
From there (Module 0 is START), the Module 1 codelab migrates from the
webapp2
web framework to Flask where the Module 1 repo folder is the FINISH point. -
The Module 2 codelab STARTs with the Module 1 code (yours or ours) and migrates away from
ndb
to Cloud NDB, and ends with the Module 2 (Python 2) FINISH repo folder. There's also has a bonus migration to Python 3, resulting in another FINISH repo folder. Once you've deployed this Python 3 code, your app is modernized and runs on the next-generation platform.
Of course, things aren't as simple in real life. Your Python 2 App Engine app may also be using Task Queues, Memcache, or many of the other original App Engine built-in services, so there will be additional migration modules (not all are available yet). With some exceptions, there's no specific order of what migrations you do next. It's just what you (or your apps) need. Here's full summary of what's currently available:
The table below summarizes migration module resources currently available to developers along with a more detailed table of contents below. Be sure to check back for updates as more resources are planned.
Module | Topic | Video | Codelab | START repo | FINISH repo |
---|---|---|---|---|---|
0 | Baseline app | TBD | N/A | N/A | Module 0 code (2.x) |
1 | Migrate to Flask | TBD | TBD | Module 0 code (2.x) | Module 1 code (2.x) |
2 | Migrate to Cloud NDB | TBD | TBD | Module 1 code (2.x) | Module 2 code (2.x) & code (3.x) |
3 | Migrate to Cloud Datastore | TBD | TBD | Module 2 code (2.x) & code (3.x) | Module 3 code (2.x) & code (3.x) |
4 | Migrate to Cloud Run with Docker | TBD | TBD | Module 2 code (2.x) & Module 3 code (3.x) | Module 4 code (2.x) & code (3.x) |
5 | Migrate to Cloud Run with Buildpacks | TBD | TBD | Module 2 code (3.x) | Module 5 code (3.x) |
6 | Migrate to Cloud Firestore | TBD | TBD | Module 3 code (3.x) | Module 6 code (3.x) |
7 | Add App Engine push tasks | TBD | TBD | Module 1 code (2.x) | Module 7 code (2.x) |
8 | Migrate to Cloud Tasks | TBD | TBD | Module 7 code (2.x) | Module 8 code (2.x) |
9 | Migrate to Python 3 (Cloud Datastore & Cloud Tasks v2) | TBD | TBD | Module 8 code (2.x) | Module 9 code (3.x) |
If there is a logical codelab to do immediately after completing one, they will be designated as NEXT. Other recommended codelabs will be listed as RECOMMENDED, and the more optional ones will be labeled as OTHERS (and usually in some kind of priority order).
-
Module 1 codelab: Migrate from
webapp2
to Flask- Required migration (can also pick your own framework)
webapp2
does not do routing thus unsupported by App Engine (even though a 3.x port exists)
- Python 2 only
- START: Module 0 code - Baseline (2.x)
- FINISH: Module 1 code - Framework (2.x)
- NEXT: Module 2 codelab - migrate to Cloud NDB
- Required migration (can also pick your own framework)
-
Module 2 codelab: Migrate from App Engine
ndb
to Cloud NDB- Required migration
- Migration to Cloud NDB which is supported by Python 3 and the next-gen platform.
- Python 2
- START: Module 1 code - Framework (2.x)
- FINISH: Module 2 code - Cloud NDB (2.x)
- Codelab bonus port to Python 3.x
- FINISH: Module 2 code - Cloud NDB (3.x)
- RECOMMENDED:
- Module 7 codelab - add App Engine (push) tasks
- OTHERS (somewhat priority order):
- Module 4 codelab - migrate to Cloud Run container with Docker
- Module 5 codelab - migrate to Cloud Run container with Cloud Buildpacks
- Module 3 codelab - migrate to Cloud Datastore
- Required migration
-
Module 7 codelab: Add App Engine (push) Task Queues to App Engine
ndb
Flask app- Not a migration: add GAE Task Queues to prepare for migration to Cloud Tasks
- Python 2
- START: Module 1 code - Framework (2.x)
- FINISH: Module 7 code - GAE Task Queues (2.x)
- NEXT: Module 8 codelab - migrate App Engine push tasks to Cloud Tasks
-
Module 8 codelab: Migrate from App Engine (push) Task Queues to Cloud Tasks v1
- Required migration
- Migration to Cloud Tasks which is supported by Python 3 and the next-gen platform.
- Note this is only push tasks... pull tasks will be handled in a different codelab.
- Python 2
- START: Module 7 code - GAE Task Queues (2.x)
- FINISH: Module 8 code - Cloud Tasks (2.x)
- NEXT: Module 9 codelab - migrate to Python 3
- Required migration
-
Module 9 codelab: Migrate a Python 2 Cloud NDB & Cloud Tasks app to a Python 3 Cloud Datastore app
- Mixed migration recommendation
- Migrating to Python 3 is required, but...
- Migrating to Cloud Datastore is optional as Cloud NDB works on 3.x; it's to give you the experience of doing it
- This codelab includes the migration in the Module 3 codelab, so skip it
- Python 2
- START: Module 8 code - Cloud Tasks (2.x)
- Python 3
- FINISH: Module 9 code - Cloud Datastore & Tasks (3.x)
- RECOMMENDED:
- Module 4 codelab - migrate to Cloud Run container with Docker
- Module 5 codelab - migrate to Cloud Run container with Cloud Buildpacks
- Mixed migration recommendation
-
Module 4 codelab: Migrate from App Engine to Cloud Run with Docker
- Optional migration
- "Containerize" your app (migrate your app to a container) with Docker
- Python 2
- START: Module 2 code - Cloud NDB (2.x)
- FINISH: Module 4 code - Cloud Run - Docker 3.x (2.x)
- Python 3
- START: Module 3 code - Cloud Datastore (3.x)
- FINISH: Module 4 code - Cloud Run - Docker (3.x)
- RECOMMENDED:
- Module 5 codelab - migrate to Cloud Run container with Cloud Buildpacks
- Optional migration
-
Module 5 codelab: Migrate from App Engine to Cloud Run with Cloud Buildpacks
- Optional migration
- "Containerize" your app (migrate your app to a container) with...
- Cloud Buildpacks which lets you containerize your app without Dockerfiles
- Python 3 only
- START: Module 2 code - Cloud NDB (3.x)
- FINISH: Module 5 code - Cloud Run - Buildpacks 3.x (3.x)
- Optional migration
-
Module 3 codelab: Migrate from Cloud NDB to Cloud Datastore
- Optional migration
- Recommended only if using Cloud Datastore elsewhere (GAE or non-App Engine) apps
- Helps w/code consistency & reusability, reduces maintenance costs
- Python 2
- START: Module 2 code - Cloud NDB (2.x)
- FINISH: Module 3 code - Cloud Datastore (2.x)
- Python 3
- START: Module 2 code - Cloud NDB (3.x)
- FINISH: Module 3 code - Cloud Datastore (3.x)
- OPTIONS (in somewhat priority order):
- Module 7 codelab - add App Engine (push) tasks
- Module 4 codelab - migrate to Cloud Run container with Docker
- Module 6 codelab - migrate to Cloud Firestore
- Optional migration
-
Module 6 codelab: Migrate from Cloud Datastore to Cloud Firestore
- Highly optional migration (WARNING: infrequent/uncommon & "expensive" migration)
- Requires new project & Datastore has better write performance (currently)
- If you must have Firestore's Firebase features
- Python 3 only
- START: Module 3 code - Cloud Datastore (3.x)
- FINISH: Module 6 code - Cloud Firestore (3.x)
- RECOMMENDED:
- Module 7 codelab - add App Engine (push) tasks
- OTHER OPTIONS (in somewhat priority order):
- Module 4 codelab - migrate to Cloud Run container with Docker
- Highly optional migration (WARNING: infrequent/uncommon & "expensive" migration)
If your original app users does not have a user interface, i.e., mobile backends, etc., but still uses webapp2
for routing, some migration must still be completed. Your options:
- Migrate to Flask (or another) web framework but keep app on App Engine
- Use Cloud Endpoints or Cloud API Gateway for your mobile endpoints
- Break-up your monolithic app to "microservices" and migrate your app to either:
- Google Cloud Functions
- Firebase mobile & web app platform (and Cloud Functions for Firebase [customized for Firebase])
- This repo, along with corresponding codelabs & videos are complementary to the official docs & code samples.
-
App Engine Migration
- Migrate from Python 2 to 3
- Migrate from App Engine
ndb
to Cloud NDB (Step 2) - App Engine
ndb
to Cloud NDB official sample app (Step 2) - Migrate from App Engine
taskqueue
to Cloud Tasks (Steps 5a-5c) - App Engine
app.yaml
to Cloud Runservice.yaml
tool (Step 4a) - Migrate from App Engine
db
tondb
("Step -1"; only for reviving "dead" Python 2.5 apps for 2.7)
-
Python App Engine
-
Google Cloud Platform (GCP)