Posted by Wesley Chun (@wescpy), Developer Advocate, Google Cloud
Background
App Engine initially launched in 2008, offering a suite of bundled companies making it handy for functions to entry a database (Datastore), caching service (Memcache), unbiased process execution (Process Queue), Google Signal-In authentication (Customers), or massive “blob” storage (Blobstore), or different companion companies. Nonetheless, apps leveraging these companies can solely run their apps on App Engine.
To extend app portability and assist Google transfer in the direction of its aim of getting essentially the most open cloud available on the market, App Engine launched its 2nd-generation service in 2018, initially eradicating these legacy companies. The newer platform permits builders to improve apps to the most recent language runtimes, reminiscent of transferring from Python 2 to three or Java 8 to 11 (and at this time, Java 17). One of many main drawbacks to the 1st-generation runtimes is that they are personalized, proprietary, and restrictive in what you need to use or cannot.
As an alternative, the 2nd-generation platform makes use of open supply runtimes, which means means to observe commonplace improvement practices, use frequent/recognized idioms, and have fewer restrictions of Third-party libraries, and obviating the necessity to copy or “vendor” them along with your code. Sadly, to make use of these newer runtimes, migrating away from App Engine companies had been required as a result of when you might improve language releases, there was no entry to bundled companies, breaking apps or requiring full rewrites, making it a showstopper for a lot of customers.
As a result of their reputation and the will to ease the improve course of for purchasers, the App Engine staff restored entry to most (however not all) of these companies in Fall 2021. As we speak’s Serverless Migration Station video demonstrates tips on how to proceed utilization of bundled companies out there to Python 3 builders.
Exhibiting App Engine customers tips on how to use bundled companies on Python 3
Performing the improve
Modernizing the standard Python 2 App Engine app seems one thing like this:
- Migrate from the
webapp2
framework (not out there in Python 3) - Port from Python 2 to three, protect use of bundled companies
- Elective migration to Cloud standalone or related Third-party companies
Step one is to maneuver to an ordinary Python net framework like Flask, Django, Pyramid, and so on. Beneath is a few pseudocode from Migration Module 1 demonstrating tips on how to migrate from webapp2
to Flask:
Step 1: Port Python 2 pattern app from webapp2 to Flask |
The important thing modifications are bolded within the above code snippets. Discover how the App Engine NDB code [the Visit
class definition plus store_visit()
and fetch_visits()
functions] are unaffected by this net framework migration. The total webapp2
code pattern may be discovered within the Module 0 repo folder whereas the finished migration to Flask pattern is situated within the Module 1 repo folder.
After your app has ported frameworks, you are free to improve to Python 3 whereas preserving entry to the bundled companies in case your app makes use of any. Beneath is pseudocode demonstrating tips on how to improve the identical pattern app to Python 3 in addition to the code modifications wanted to proceed to make use of App Engine NDB:
Step 2: Port pattern app to Python 3, preserving use of NDB bundled service |
The NDB code can also be left untouched on this migration. Not all the bundled companies function such a hands-free migration, and we hope to cowl a number of the extra advanced ones forward in Module 22. Java, PHP, and Go customers have it even higher, requiring fewer or no code modifications in any respect. The Python 2 Flask pattern is situated within the Module 1 repo folder, and the ensuing Python 3 app may be discovered within the Module 1b repo folder.
The fast advantage of step two is the flexibility to improve to a extra present model of language runtime. This leaves the third step of migrating off the bundled companies as non-compulsory, particularly if you happen to plan on staying on App Engine for the long-term.
Further choices
In case you determine emigrate off the bundled companies, you are able to do so by yourself timeline. It must be a consideration must you ever wish to transfer to fashionable serverless platforms reminiscent of Cloud Capabilities or Cloud Run, to lower-level platforms since you need extra management, like GKE, our managed Kubernetes service, or Compute Engine VMs.
Step three can also be the place the remainder of the Serverless Migration Station content material could also be helpful:
*code samples and codelabs out there;Â movies forthcoming
So far as transferring to fashionable serverless platforms, if you wish to break aside a big App Engine app into a number of microservices, contemplate Cloud Capabilities. In case your group has added containerization as a part of your software program improvement workflow, contemplate Cloud Run. It is appropriate for apps if you happen to’re conversant in containers and Docker, however even if you happen to or your staff do not have that have, Cloud Buildpacks can do the heavy lifting for you. Listed below are the related migration modules to discover:
Wrap-up
Early App Engine customers admire the comfort of the platform’s bundled companies, and after listening to consumer suggestions, including them again to 2nd-generation runtimes is one other method we may help builders modernize their apps. Whether or not upgrading to newer language runtimes to remain on App Engine and proceed to make use of its bundled companies, migrating to Cloud standalone merchandise, or shifting to different serverless platforms, the Google Cloud staff goals to supply the instruments to assist streamline your modernization efforts.
All Serverless Migration Station content material (codelabs, movies, supply code [when available]) may be accessed at its open supply repo. Whereas our content material initially focuses on Python customers, the Cloud staff is engaged on protecting different language runtimes, so keep tuned. As we speak’s video encompasses a particular visitor to supply a teaser of what to anticipate for Java. For extra video content material, try the broader Serverless Expeditions collection.