Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

Converting Backends to Services

The original App Engine architecture is based on a single frontend instance with optional backend instances. If you have an application that uses backends, you might want to convert the backends to a service format to take full advantage of the additional functionality that services provide, such as the ability to version backends.

App Engine automatically runs an existing backend as a new, non-default version of the default service. Resident backends are assigned manual scaling and dynamic backends are assigned basic scaling.

You can convert backend instances to named services that are versioned and have explicit scaling type and instance classes. You must replace the original backends.yaml file with multiple .yaml files as shown below.

For example, here is a fragment from a .yaml file that defines three backends (memdb, worker, and cmdline):

- name: memdb
  class: B8
  instances: 5
- name: worker
  options: failfast
- name: cmdline
  options: dynamic

To convert these backends to services, create a separate .yaml file for each service:

In memdb.yaml:

service: memdb
version: uno
instance_class: B8
  instances: 5

In worker.yaml:

service: worker
version: uno
# For failfast functionality, please use the ‘X-AppEngine-FailFast’ header on requests made to this service.
  instances: 1
# If a service has an _ah/start handler, it should be listed first.
- url: /_ah/start

Note that the original definition of the worker backend used the start: tag to bind the script to the _ah/start path. For services, this binding is defined as a handler with the explicit _ah/start path. Additionally, if there's more than one handler, the _ah/start handler should be listed first.

In cmdline.yaml:

service: cmdline
version: uno
  max_instances: 1

The Python SDK contains a script that can perform these transformations for you. Given two .yaml files, one for the app and one for its backends, it creates new .yaml files defining services for each backend. Using the migration example above, assume the original file defining the three backends is called backends.yaml, and the file defining the main app is app.yaml. The script would generate three new .yaml files: memdb.yaml, worker.yaml, and cmdline.yaml. Here is how to call it:

[PATH_TO_SDK]/google-cloud-sdk/platform/google_appengine/ backends.yaml app.yaml