Posted by Wesley Chun (@wescpy), Developer Advocate, Google Cloud
migrate the App Engine Customers to Cloud Id Platform |
Understanding the general migration
Total, Module 21 options main adjustments to the Module 20 pattern app, implementing a transfer from App Engine bundled providers (NDB & Customers) to standalone Cloud providers (Cloud Datastore & Id Platform). Id Platform does not know something about App Engine admins, in order that have to be constructed, requiring using the Cloud Useful resource Supervisor API. Apps depending on Python 2 have further required updates. Let’s talk about in a bit extra element.
Migration “components”
The next adjustments to the pattern app are required:
Migrate from App Engine Customers (server-side) to Cloud Id Platform (client-side)
- Migrate from App Engine NDB, the opposite bundled service utilized in Module 20, to Cloud NDB (requires use of the Cloud Datastore API)
- Use the Cloud Useful resource Supervisor* (by way of its API) to fetch the Cloud mission’s IAM permit coverage to collate the set of App Engine admin customers for the app.
- Use the Firebase Admin SDK to validate whether or not the person is an App Engine admin
- Migrate from Python 2 to three (and probably again to Python 2 [more on this below])
*On the time of this writing, the Useful resource Supervisor documentation solely options setup directions for accessing the API from the lower-level Google APIs consumer library quite than the Useful resource Supervisor consumer library. To discover ways to arrange the latter, go to the Useful resource Supervisor consumer library documentation straight. The lower-level consumer library ought to solely be utilized in circumstances when a Cloud consumer library does not exist or does not have the options your app wants. One such use case is Python 2, and we’ll be protecting that shortly.
Transfer from App Engine bundled providers to standalone Cloud providers
The NDB to Cloud NDB migration is equivalent to the Module 2 migration content material, so it is not lined in-depth right here in Module 21. The first focus is on switching to Id Platform to proceed supporting person logins in addition to implementing use of the Useful resource Supervisor and Firebase Admin SDK to construct a proxy for recognizing App Engine admin customers as supplied by the Customers service. Under is pseudocode implementing the important thing adjustments to the primary utility the place new or up to date traces of code are bolded:
Migrating from App Engine Customers to Cloud Id Platform(click on to enlarge) |
The important thing variations to notice:
- The server-side Customers service code vanishes from the primary utility, shifting into the (client-side) internet template (not proven right here).
- Virtually the entire new code within the Module 21 app above is for recognizing App Engine admin customers. There are not any adjustments to app operations or knowledge fashions apart from Cloud NDB requiring use of Python context managers to wrap all Datastore code (utilizing Python with blocks).
Full variations of the app earlier than and after the updates might be discovered within the Module 20 (Python 2) and Module 21 (Python 3) repo folders, respectively. Along with the video, you’ll want to try the Id Platform documentation in addition to the Module 21 codelab which leads you step-by-step by means of the migrations mentioned.
Except for the mandatory coding adjustments in addition to shifting from server-side to client-side, be aware that the Customers service utilization is roofed by App Engine’s pricing mannequin whereas Id Platform is an impartial Cloud service billed by MAUs (month-to-month lively customers), so prices must be taken under consideration if migrating. Extra info might be discovered within the Id Platform pricing documentation.
Python 2 issues
With the sundown of Python 2, Java 8, PHP 5, and Go 1.11, by their respective communities, Google Cloud has assured customers by expressing continued long-term help of those legacy App Engine runtimes, together with sustaining the Python 2 runtime. So whereas there isn’t any present requirement for customers emigrate, builders themselves are expressing curiosity in updating their purposes to the most recent language releases.
The first Module 21 migration mechanically features a port from Python 2 to three as that is the place most builders are headed. For these with dependencies requiring remaining on Python 2, some further effort is required:
The codelab covers this backport in-depth, so try the particular part for Python 2 customers for those who’re on this state of affairs. If you happen to do not wish to give it some thought, simply head to the repo for a working Python 2 model of the Module 21 app.
Wrap-up
Module 21 options migrations of App Engine bundled providers to acceptable standalone Cloud providers. Whereas we suggest customers modernize their App Engine apps by shifting to the most recent choices from Google Cloud, these migrations are usually not required. In Fall 2021, the App Engine crew prolonged help of most of the bundled providers to 2nd era runtimes (which have a 1st era runtime), that means you do not have emigrate to standalone providers earlier than porting your app to Python 3. You may proceed utilizing App Engine NDB and Customers in Python 3 as long as you retrofit your code to entry bundled providers from next-generation runtimes. Then do you have to decide emigrate, you are able to do so by yourself timeline.