Select Page

How to use the App Engine Users service (Module 20)

Google Developers
Published: December 21, 2022

Posted by Wesley Chun (@wescpy), Developer Advocate, Google Cloud

Introduction and background

The Serverless Migration Station video series and corresponding codelabs aim to help App Engine developers modernize their apps, whether it’s upgrading language runtimes like from Python 2 to 3 and Java 8 to 17, or to move laterally to sister serverless platforms like Cloud Functions or Cloud Run. For developers who want more control, like being able to SSH into instances, Compute Engine VMs or GKE, our managed Kubernetes service, are also viable options.

In order to consider moving App Engine apps to other compute services, developers must move their apps away from its original APIs (now referred to as legacy bundled services), either to Cloud standalone replacement or alternative 3rd-party services. Once no longer dependent on these proprietary services, apps become much more portable. Apps can stay on App Engine while upgrading to its 2nd-generation platform, or move to other compute platforms as listed above.

How to use the App Engine Users service

Adding use of Users service

The sample app’s basic functionality consists of registering each page visit in Datastore and displaying the most recent visits. The Users service helps apps support user logins, App Engine administrative (“admin'”) users. It also provides convenient functions for generating login/logout links and retrieving basic user information for logged-in users. Below is a screenshot of the modified app which now supports user logins via the user interface (UI):

Sample app now supports user logins and App Engine admin users (click to enlarge) 

Below is the pseudocode reflecting the changes made to support user logins for the sample app, including integrating the Users service and updating what shows up in the UI:

  • If the user is logged in, show their “nickname” (display name or email address) and display a Logout button. If the logged-in user is an App Engine app admin, also display an “admin” badge (between nickname and Logout button).

  • If the user is not logged in, display the username generically as “user”, remove any admin badge, and display a Login button.

Because the Users service is primarily a user-facing endeavor, the most significant changes take place in the UI, whereas the data model and core functionality of registering visits remain unchanged. The new support for user management primarily results in additional context to be rendered in the web template. New or altered code is bolded to highlight the updates.

Table showing code 'Before'(Module 1) on left, and 'After' (Module 20) on the right
 Adding App Engine Users service usage to sample app (click to enlarge)


Today’s “migration” consists of adding usage of the App Engine Users service to support user management and recognize App Engine admin users, starting with the Module 1 baseline app and finishing with the Module 20 app. To get hands-on experience doing it yourself, try the codelab and follow along with the video. Then you’ll be ready to upgrade to Identity Platform should you choose to do so.

If you do want to move to Identity Platform, see the Module 21 content, including its codelab. All Serverless Migration Station content (codelabs, videos, and source code [when available]) are available at its open source repo. While we’re initially focusing on Python users, the Cloud team is covering other runtimes soon, so stay tuned. Also check out other videos in the broader Serverless Expeditions series.