Using the Modules API

The Modules API provides functions that return information about the current operating environment (module, version, and instance).

The Modules API also has functions that retrieve the address of a module, a version, or an instance. This allows an application to send requests from one instance to another, in both the development and production environments.

The following code sample shows how to get the module name and instance id for a request:

import ""

func handler(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)
	module := appengine.ModuleName(ctx)
	instance := appengine.InstanceID()

	log.Infof(ctx, "Received on module %s; instance %s", module, instance)

The instance ID of an automatic scaled module will be returned as a unique base64 encoded value, e.g. e4b565394caa.

You can communicate between modules in the same app by fetching the hostname of the target module:

hostname, err := appengine.ModuleHostname(ctx, "my-backend", "", "")
if err != nil {
	// ...
url := "http://" + hostname + "/"
// ...

You can also use the URL Fetch service.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

App Engine standard environment for Go