Teresa Salazar
Teresa Salazar

Reputation: 63

How to get URL of deployed App Engine Project

I have deployed my app in App Engine using maven (https://cloud.google.com/appengine/docs/flexible/java/using-maven)

How can I programmatically get the URL of the APP? I know it follows this format https://PROJECT_ID.REGION_ID.r.appspot.com. However, I do not know the region Id. If there is no way to get the URL, is there a way to get the region ID?

edit

I found this to be useful for this purpose: https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps/get

Upvotes: 4

Views: 2618

Answers (2)

Arun Shinde
Arun Shinde

Reputation: 1185

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";

}

Upvotes: 1

Sri
Sri

Reputation: 318

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

gcloud app browse

Upvotes: 3

Related Questions