Migrating Services from the Standard Environment to the Flexible Environment

The App Engine flexible environment does not provide the API libraries present in the App Engine SDK. If you decide to migrate your application from the App Engine standard environment to the flexible environment, you must update your code to use services and APIs that are available across all Google Cloud Platform environments.

See the following sections for instructions on how to migrate specific services and APIs from the standard environment to the flexible environment.

App identity

When running on the flexible environment, you can use a combination of environment variables and the Google Compute Engine Metadata service to obtain information about your application:

Application info How to access
Application / project ID Either the GCLOUD_PROJECT environment variable or the /project/project-id resource in the metadata server
Default hostname App Engine Admin API apps.get method
Service account name The /instance/service-accounts resource in the metadata server
OAuth 2.0 access token The /instances/service-accounts resource in the metadata server. See the Compute Engine Authenticating with service account credentials documentation

The following functionality is not directly available:

  • There is no default Google Cloud Storage bucket for your project. However, you can easily create a Cloud Storage bucket using the project ID as the bucket name and use the GCLOUD_PROJECT environment variable in your application as the bucket name.
  • You cannot sign blobs with the default service account. You can work around this by using the Google Identity and Access Management (IAM) API or by providing a service account private key to your application when deploying.
  • Similarly, there is no built-in API to obtain public certificates for verifying signatures. However, every service account's public certificates are available at https://www.googleapis.com/robot/v1/metadata/x509/{service account email}.

Background threads

Because the flexible environment has no sandbox limitations, you’re free to create threads or processes that live outside of the request environment. You typically do not need to use anything other than your language’s built-in threading or multiprocessing tools.

Blobstore

Usage of the Blobstore service has largely been replaced in both standard and flexible environments by Cloud Storage. Use the Google Cloud client libraries to store and retrieve data in Cloud Storage.

For more information, see the following guide:

Capabilities

There is no functionality similar to the Capabilities service available outside of the standard environment.

Channel

The Channel service is not available outside of the standard environment. There is no direct alternative, however, Firebase's Realtime Database and Cloud Messaging provide functionality similar to the Channel service.

Like the standard environment, the flexible environment does not support websockets. If you need to use websockets you can use Compute Engine or Container Engine.

Cloud Datastore

You can access Google Cloud Datastore from anywhere using the Cloud Datastore API. Use the Google Cloud client libraries to store and retrieve data from Cloud Datastore.

The same Cloud Datastore data is available regardless of if you use the App Engine libraries, the Google Cloud client libraries, or call the API directly.

At this time ORM libraries that available in the standard environment such as ndb and Objectify are not supported outside of the standard environment.

For more information, see the following guide:

Images

The Images service is not available outside of the standard environment. However, you can easily serve images directly from your application or directly from Cloud Storage.

If you need to do image processing, you can install and use any image processing library such as ImageJ2, imgscalr, or thumbnailator

The Images service also provided functionality to avoid dynamic requests to your application by handling image resizing using a serving URL. If you want similar functionality, you can generate the re-sized images ahead of time and upload them to Cloud Storage for serving. Alternatively, you could use a third-party content delivery network (CDN) service that offers image resizing.

For more resources, see the following guides:

Logging

Like the standard environment, logging works automatically in the flexible environment. However, the logs are collected in a different format. Logs will not be bundled by requests and logs from stdout and stderr are collected separately.

If you want more control over application logging, the ability to group logs, and the ability to log additional metadata, you can use the Stackdriver Logging API directly with the Google Cloud client libraries.

For more details, see the following guide:

Mail

The App Engine Mail service is not available outside the standard environment. You will need to use a third-party mail provider such as SendGrid, Mailgun, or Mailjet to send email. All of these services offer APIs to send email from applications running anywhere.

The following guides show how to use these services with the flexible environment:

Memcache

The Memcache service is currently not available for the App Engine flexible environment. An alpha version of the memcache service will be available shortly. If you would like to be notified when the service is available, fill out this early access form.

If you need access to a memcache service immediately, you can use the third party memcache service from Redis Labs. To access this service, see Caching Application Data Using Redis Labs Memcache.

You can also use Redis Labs Redis Cloud, a third party fully-managed service. To access this service, see Caching Application Data Using Redis Labs Redis.

Modules

The Modules API is not available outside of the standard environment. However, you can use a combination of environment variables and the App Engine Admin API to obtain information about and modify your application's running services:

Service information How to access
Current service name GAE_SERVICE environment variable
Current service version GAE_VERSION environment variable
Current instance ID GAE_INSTANCE environment variable
Default hostname App Engine Admin API apps.get method
List of services App Engine Admin API apps.services.list method
List of versions for a service App Engine Admin API apps.services.versions.list method
Default version for a service, including any traffic splits App Engine Admin API apps.services.get method
List of running instances for a version App Engine Admin API apps.services.versions.instances.list method

You can also use the App Engine Admin API to deploy and manage services and versions in your application.

Namespaces

Outside of the standard environment, only Google Cloud Datastore supports multitenancy directly. For other services, you will need to handle multitenancy manually. To have completely isolated instances of services, you can create new projects programmatically using the Cloud Resource Manager API and access resources across projects.

OAuth

The OAuth service is not available in the flexible environment. If you need to verify OAuth 2.0 tokens you can do so with the oauth2.tokeninfo method of the OAuth 2.0 API.

Remote

The Remote API service is not applicable to the flexible environment. The majority of backing services, such as Cloud Datastore, that are accessible from the flexible environment are also accessible from anywhere.

The Search service is currently unavailable outside of the standard environment. You can host any full-text search database such as ElasticSearch on Google Compute Engine and access it from both the standard and flexible environments.

Sockets

The flexible environment has no sandbox restrictions, so you can open and use outbound sockets normally.

Task Queues

The Task Queue service has limited availability outside of the standard environment. If you want to use the service outside of the standard environment, you can sign up for the Cloud Tasks alpha.

Outside of the standard environment, you can't add tasks to push queues, but a service running in the flexible environment can be the target of a push task. You can specify this using the target parameter when adding a task to queue or by specifying the default target for the queue in queue.xml.

In many cases where you might use pull queues, such as queuing up tasks or messages that will be pulled and processed by separate workers, Cloud Pub/Sub can be a good alternative as it offers similar functionality and delivery guarantees.

URL Fetch

The flexible environment has no sandbox restrictions, so you can use any HTTP library. We recommended using The Google HTTP Client Library for Java or OkHttp.

Users

The Users service is not available outside of the standard environment. You can use any HTTP-based authentication mechanism in the flexible environment, such as:

Note that because the Users service is not available, it is not possible to use appengine-web.xml. to make URLs accessible only by administrators. You will need to handle this logic within your application.

XMPP

The XMPP service is not available outside of the standard environment. However, you can run an XMPP server such as ejabberd in the flexible environment using custom runtimes.

If you are using XMPP for real-time communication, consider non-XMPP alternatives such as Firebase and Cloud Pub/Sub.

What's next

For an overview of the key differences between the flexible environment and the standard environment with guidelines for applications that use both environments, see App Engine Flexible Environment for Users of App Engine Standard Environment.

Send feedback about...

App Engine flexible environment for Java docs