Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 788
Teresa Salazar Avatar asked Oct 27 '25 10:10

Teresa Salazar


2 Answers

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

gcloud app browse
like image 74
Sri Avatar answered Oct 30 '25 01:10

Sri


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

}
like image 40
Arun Shinde Avatar answered Oct 29 '25 23:10

Arun Shinde