Determining if running local on App Engine Standard with Java 11

337 views
Skip to first unread message

Tom Harris

unread,
Apr 7, 2021, 10:45:20 AM4/7/21
to Google App Engine
Hi all:

I am in the process of upgrading all our App Engine 8 services to 11, but I am running into an issue. We use the `SystemProperty.environment.value()` to determine if we are running locally on one of our developer machines or out in the cloud, however since upgrading to java 11, the value is always just null.

What is the equivalent code for App Engine 11? There doesn't seem to be any documentation for this at all.

Thanks,
Tom Harris
Tech Lead
TerraTrue, Inc.

Elliott (Cloud Platform Support)

unread,
Apr 7, 2021, 2:42:32 PM4/7/21
to Google App Engine
Hello Tom,

Thank you for your question regarding “SystemProperty.environment.value()” not being available for Java 11. Since upgrading to java 11, the value output of this code is always just null.

For the community, this code is used to know if you are running the code locally or out in the cloud. You may see the details here.

You would like to know the equivalent code for App Engine 11 because there doesn't seem to be any documentation for this feature at all.

I was able to verify your claim in public documentation. The information I researched is very old and does not appear to be included in the Java 11 Runtime as you need it.

So this is an opportunity to request this functionality but to add value to this feature request, how would you implement it?

We may use your ideas to get this done but please note that there is no guarantee that it will be implemented but we will take a look and consider your request seriously.

Tom Harris

unread,
Apr 8, 2021, 5:33:31 PM4/8/21
to google-a...@googlegroups.com
I have found this works for my case, as null is being returned when running locally in spring boot via maven.

 null = ServiceOptions.getAppEngineAppId()

In any non-static context, using the spring profile is the way to go.

Thanks,
Tom Harris
Tech Lead
TerraTrue, Inc.
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/3a358b5b-dbef-4f53-9685-f94ec2cb9033n%40googlegroups.com.

David Dadon

unread,
Apr 18, 2021, 9:13:56 AM4/18/21
to Google App Engine
I did not check but there is the metadata server on AppEngine with Java 11[1]

- On GCP it would return you the project ID assigned to your project
- It would fail locally

So you could wrap this in a method to tell you if you are running on GCP or not.

There are also some Environment variables[2] set by the runtime. It would be a more straightforward solution but I don't know if they are also set locally or not.
Reply all
Reply to author
Forward
0 new messages