How to get URL of deployed App Engine Project

Viewed 603
2 Answers

This command will get the URL of the deployed App Engine:

gcloud app browse

I'm using this code on my production env to identify the URL. Getting of REGIONID dynamically using code is not possible for now. At least in my current SDK it is not available. Someday they will do that.

For now REGIONID.r is not mandatory in the URL as per the Google documentation. It might be required in future projects. This code will work for you. https://cloud.google.com/appengine/docs/standard/python/how-requests-are-routed#region-id

import com.google.appengine.api.modules.ModulesServiceFactory;
import com.google.appengine.api.utils.SystemProperty;
import com.google.apphosting.api.ApiProxy;

public static void main(String[] args) {

    String projectId = ApiProxy.getCurrentEnvironment().getAppId().indexOf("~")>-1?
                ApiProxy.getCurrentEnvironment().getAppId().split("~")[1]:ApiProxy.getCurrentEnvironment().getAppId();
    ModulesService ssf = ModulesServiceFactory.getModulesService();
    String url = null;
    if(SystemProperty.environment.value()!=SystemProperty.Environment.Value.Production) {
        url = "http://localhost:PORT_NUMBER";
    }
    if(ssf.getDefaultVersion(ssf.getCurrentModule()).equals(ssf.getCurrentVersion())) {
        //This is default version
        url = "https://" + projectId + ".appspot.com";
    }
    //The URL with the current version ID  
    url = "https://" + ssf.getCurrentVersion() + "-dot-" + projectId + ".appspot.com";
    //The URL with the module name, current version name
    url = "https://" + ssf.getCurrentVersion() + "-dot-" + ssf.getCurrentModule() + "-dot-" + projectId + ".appspot.com";

}
Related