Testing and deploying your upgraded app in Python 3

Region ID

The REGION_ID is an abbreviated code that Google assigns based on the region you select when you create your app. The code does not correspond to a country or province, even though some region IDs may appear similar to commonly used country and province codes. For apps created after February 2020, REGION_ID.r is included in App Engine URLs. For existing apps created before this date, the region ID is optional in the URL.

Learn more about region IDs.

After you upgrade your app to be compatible with both Python 2 and Python 3:

  1. Test the app in a local Python 3 environment.

  2. Deploy and test in App Engine without shifting traffic to your app.

  3. Migrate traffic to your app.

You may need to spend significant time fixing compatibility issues that aren't visible until you run your upgraded app in a Python 3 environment.

To avoid using production data and Google Cloud quota during testing, you can use the following emulators:

Other Google Cloud services such as Cloud Storage and Memorystore don't provide emulators.

Testing locally

To test your app's functionality before deploying, follow the instructions for running locally in the Python 3 runtime.

Testing on App Engine before shifting traffic

Before routing traffic to your upgraded Python app, deploy the app to the App Engine Python 3 runtime for another round of testing. For example, to test your app's default service:

  1. Make sure you've updated the app's configuration files for compatibility with the Python 3 runtime.

    Don't change environment variables that send requests to emulators or test databases until you're ready to shift traffic to your app.

  2. Deploy your new version, but prevent traffic from automatically routing to the new version:

    gcloud app deploy --no-promote

  3. Access your new version by navigating to the following URL:

    https://VERSION_ID-dot-default-dot-PROJECT_ID.REGION_ID.r.appspot.com

Now you can test your new version in the App Engine runtime environment. You can debug your application by viewing its logs. For more information, see Writing Application Logs.

Requests sent to https://PROJECT_ID.REGION_ID.r.appspot.com are routed to the version previously configured to receive traffic.

To test new versions of other services, follow the same process, but replace default in the URL with your service's name:

https://VERSION-dot-SERVICE-dot-PROJECT_ID.REGION_ID.r.appspot.com

For more information about targeting specific services and versions, see How Requests are Routed.

Migrating traffic to your app

When you're ready to send traffic to the new version:

  1. Update environment variables in your app.yaml file to send requests to your production databases and other services instead of any emulators or test data you were using.

  2. Prevent traffic being automatically routed to your new version upon deployment:

    gcloud app deploy --no-promote

  3. When you've confirmed that your app is interacting with your production databases and datastores, use the Google Cloud console to migrate traffic:

    Manage versions

    Select the latest version of your upgraded app and click Migrate traffic.