Is there a way to access the Google Cloud metadata service from AppEngine Standard to configure runtime?

I would like to access the metadata service from the App Engine Standard application. I tried to do urlfetch prior to http://metadata.google.internal/computeMetadata/v1/project/attributes and returned DNS lookup failed :

  logging.info(urlfetch.fetch('http://metadata.google.internal/computeMetadata/v1/project/attributes/').content) 

Is it possible? I would like to share the configuration between App Engine Flex and standard code in the same project.

+5
source share
2 answers

Some friendly people on the GCP slack channel pointed me to the RuntimeConfig API to share the configuration of several types of services on Google Cloud. This solves the problem of sharing the configurations I was looking for.

For the curious you need:

  • Enable API in the API for your Google Cloud Project
  • Run some gcloud commands:

     gcloud beta deployment-manager runtime-configs create foo-credentials gcloud beta deployment-manager runtime-configs variables set "bar-variable-name" "baz-value" --config-name "foo-credentials"``` 
  • Add the python library google-cloud-runtimeconfig to your project (I did this via pip )

  • Add python code to extract the variable at runtime:

     config_client = runtimeconfig.Client() config = config_client.config('foo-credentials') bar = config.get_variable('bar-variable-name')``` 
+6
source

No, you cannot access metadata (GCE-specific) from a standard GAE instance, since it is not a GCE VM / instance. From Obtaining Metadata (highlighted by me):

You can request the contents of a metadata server by querying the following root URLs from a virtual machine instance . Use the URL http://metadata.google.internal/computeMetadata/v1/ to make requests to the metadata server.

The DNS failure that you see for metadata.google.internal is a likely indicator that it has a special host DNS record, available only within the network or GCE machine.

But in the general case, you can exchange files through the GAE services / modules, symbolizing the same file (ideally located in the application directory) inside each of them that requires it. See the examples here: Entity sharing between App Engine modules and here: fooobar.com/questions/998174 / ...

While the flex service / module uses the same file of the file (s) in the same way as the standard one, this method should work for them too, i.e. you can share configurations by sharing appengine_config.py , for example.

+2
source

Source: https://habr.com/ru/post/1260903/


All Articles