Compute Engine metadata server

Google Compute Engine provides a method for storing and retrieving metadata in the form of the metadata server. This service provides a central point to set metadata in the form of key-value pairs, which is then provided to virtual machines at runtime. Metadata can be configured through API calls, through the Cloud Console, or through the gcloud compute command group.

App Engine instances can leverage the metadata server to securely retrieve project-wide metadata in different ways depending on whether they are running in the standard or flexible environment. Services running in the App Engine flexible environment are backed Compute Engine VMs, making it possible to retrieve custom metadata through local API calls to http://metadata/cumputeMetadata/v1/attributes/<KEY>. Additionally, Google offers metadata server client libraries for many languages which simplifies the retrieval process.

For services running in the App Engine flexible environment, retrieving metadata requires making API calls to the metadata server API directly (http://metadata.google.internal). This is functionally similar to the flexible environment, but requires clients to handle authentication at the request level. The metadata server is not provided as part of the App Engine development server, so developers will need to check if the application is running on App Engine before reading values. Also note that metadata is provided as read-only, meaning services cannot create or update key value pairs.

The metadata server is a fairly deep topic, and can be used in a number of ways. Values can be retrieved on an individual basis, or as an object by recursively reading nested metadata values. We'll take a closer look at the metadata server in Chapter 7Google Compute Engine.