Test and deploy your application

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.

Learn how to run your application locally, deploy it, and test on App Engine.

Run locally

To test your application before deploying, run your application in your local environment with the development tools that you usually use.

Deploy your application

Deploy your application to App Engine by using the gcloud app deploy command.

The Cloud Build service automatically builds your deployment into a container image and deploys the image to the App Engine flexible environment. The container includes any local modifications that you've made to the runtime image.

To programmatically deploy your apps, use the Admin API.

Before you begin

Before you can deploy your application:

Deploy a service

You deploy your application to App Engine by deploying versions of your application's services and each of their configuration files.

  • You can deploy the other configuration files of your service by targeting and deploying each file separately, for example:

    gcloud app deploy cron.yaml
    gcloud app deploy dispatch.yaml
    gcloud app deploy index.yaml
    
  • To specify a custom version ID, use the --version flag.

  • To prevent traffic from being automatically routed to the new version, use the --no-promote flag.

  • To deploy to a specific Google Cloud project, use the --project flag.

For example, to deploy the service defined by the app.yaml file to a specific Google Cloud project, assign the service a custom version ID and prevent traffic from being routed to the new version:

gcloud app deploy --project PROJECT_ID --version VERSION_ID --no-promote

For more information, see the gcloud app deploy reference.

You can set properties for the gcloud CLI and create and manage SDK configurations so you don't need to specify flags such as --project every time you deploy.

Ignore files

You can use a .gcloudignore file to specify files and directories not to upload to Google Cloud when you deploy your services. This is useful for ignoring build artifacts and other files that don't need to be uploaded with your deployment.

Learn more about the syntax of the .gcloudignore file in the gcloud reference.

Manually build a container for deployment

To build your container images outside of Google Cloud:

  1. Upload your images to an Artifact Registry repository. For more information, see Push and pull images.
  2. Deploy to App Engine with the gcloud app deploy command.

For example, if you build your container images locally with Docker, you can push those images to the Artifact Registry and specify the URL of your image in the --image-url flag of the command:

gcloud app deploy --image-url LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE

Replace:

  • LOCATION with the location of the repository where the image is stored.

  • PROJECT-ID with your Google Cloud project ID.

  • REPOSITORY with the name of the repository where the image is stored.

  • IMAGE with the name of your container image.

Use automated continuous deployment pipelines

You can use Cloud Build to automate deployments in continuous deployment pipelines. For more information, see Deploying to App Engine and Create and manage build triggers in the Cloud Build documentation.

Docker base images

If you'd like to build a custom runtime application, see Create a Docker file.

View your application

After you deploy your application to App Engine, you can run the following command to launch your browser and view it at https://PROJECT_ID.REGION_ID.r.appspot.com:

gcloud app browse

Test on App Engine

Before configuring a new version to receive traffic, you can test it on App Engine. For example, to test a new version of your default service:

  1. Deploy your new version and include the --no-promote flag:

    gcloud app deploy --no-promote

  2. 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 in the Google Cloud console Logs Explorer. For more information, see Writing Application Logs.

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

  3. When you want to send traffic to the new version, use the Google Cloud console to migrate traffic:

    Manage versions

    Select the version you just deployed and click Migrate traffic.

You can use the same process to test new versions of other services by replacing 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.

Use build environment variables

You can set build environment variables for runtimes that support buildpacks.

Build environment variables are key-value pairs that you can specify to configure the buildpack you use to deploy your app. For example, you might want to specify compiler options.

Before you begin:

  • Keys must start with an uppercase ASCII letter, and can include uppercase ASCII letters, digits, and underscores.
  • You should avoid creating any variables with a GOOGLE_* key prefix.
  • The following keys are reserved for Google's use:
    • GOOGLE_RUNTIME
    • GOOGLE_RUNTIME_VERSION
    • GOOGLE_ENTRYPOINT
    • GOOGLE_DEVMODE
  • You can use any key that is supported by buildpacks.

To use environment variables with buildpacks, specify the build_env_variables field in your app.yaml file.

Learn more about buildpacks.

Use Cloud Trace

Cloud Trace is useful for understanding how requests propagate through your application. You can inspect detailed latency information for a single request or view aggregate latency for your entire application.

You can view trace details. In the Trace explorer, you can filter by your specific App Engine service and version.

Troubleshoot

The following are common error messages that you might encounter when deploying apps:

PERMISSION_DENIED: Operation not allowed
The "appengine.applications.create" permission is required.
If the Google Cloud project does not include the required App Engine application, the gcloud app deploy command can fail when it tries to run the gcloud app create command. Only accounts with Owner role have the necessary permissions to create App Engine applications.
502 Bad Gateway
The Google Cloud project can fail to start if the app.yaml is misconfigured. Check the app logs for more detailed error messages.
[13] An internal error occurred while creating a Cloud Storage bucket.

App Engine creates a default Cloud Storage multi-regional bucket on your behalf on the same region where it creates your application. It requires this bucket to store the contents of your application. The error returns when this bucket cannot be created, such as in the following scenarios:

For example, if your App Engine app is created in the europe-west region, even though the region maps to the europe-west1 locations, you must modify the constraint to allow resources in the in:eu-locations, which includes all the EU regions. This is required because the App Engine-created buckets are multi-regional. If your App Engine app is created in the US region, you must allow in:us-locations, and if your app is created in the ASIA regions, you must allow in:asia-locations.

[13] An internal error occurred.

This error can occur if you are deploying your service with a network configuration that uses a Shared VPC setup. Try the following:

  1. Ensure that your app.yaml configuration is valid.
  2. Ensure that your App Engine flexible environment fulfills all the requirements for a Shared VPC setup. See Using the App Engine flexible environment on a Shared VPC network.
  3. Be sure that you have configured service accounts present in your project. If not, you must restore the accounts. The subnet region in the Shared VPC host project must match the location where your App Engine environment was created.

If the issue persists, redeploy your service by using the Google Cloud SDK. Be sure to add the --verbosity=debug flag. Contact Google Cloud Support and provide the command's output.

IP space of {USER_SUBNETWORK_NAME} is exhausted and needs to be expanded.

If the deployment fails with this error message, the network configured for the App Engine service doesn't have addresses left to allocate for the new instances of the service. To resolve the issue, expand the VPC ranges on the subnet that is configured for your App Engine flexible environment service.