Serving different versions and services of App Engine on the same custom domain

A guide on how to utilize GCP load balancer constructs to serve multiple versions and services on App Engine using a single custom domain name.

A common question seen on the Internet is about how to use a custom domain name with multiple versions of the same or several App Engine services in GCP. For example -

  • example.com -> default version of an App Engine service called Test
  • example.com/abc -> abc version of an App Engine service called Test
  • example.com/xyz -> default version of an App Engine service called XYZ

This desired functionality can be achieved in GCP by sending HTTP requests to appropriate URLs for services and versions in App Engine environment. GCP offers URLs on appspot.com domain for each App Engine service and version in the following format -

VERSION-dot-SERVICE-dot-PROJECT_ID.REGION_ID.r.appspot.com

Assuming that the project ID is testproject and region of deployment is us-central1, the mapping in case of our example scenarios above looks like -

  • example.com -> default-dot-test-dot-testproject.us-central1.r.appspot.com
  • example.com/abc -> abc-dot-test-dot-testproject.us-central1.r.appspot.com
  • example.com/xyz -> default-dot-xyz-dot-testproject.us-central1.r.appspot.com

Now, these URLs form the backends as Internet Network Endpoint Groups (NEGs) for backend services of a GCP External Application Load Balancer. With this setup, your users can still access your application on your custom domain name (part of the URL map), but the load balancer terminates the connection and initiates a new connection to the backend Internet NEG (the appropriate URL) from itself. Ultimately, the response from App Engine service is sent back to the original client of the customer that initiated the request to the load balancer IP.