
Answer-first summary for fast verification
Answer: Use HTTP requests to query the available metadata server at the http://metadata.google.internal/ endpoint with the Metadata-Flavor: Google header.
To securely and efficiently obtain the project ID and region in a Cloud Run application, the metadata server (http://metadata.google.internal/) is the recommended approach. Option A uses direct HTTP requests to this server with the required header, which is both secure (internal endpoint) and performant (low-latency access). Other options are less ideal: B relies on manual configuration (error-prone and static), C adds unnecessary I/O overhead, and D involves external API calls (slower and requires permissions).
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You are hosting a web application on Cloud Run and need to securely retrieve the application's project ID and region at runtime to display to users. You want to implement the most performant method. What is the recommended approach?
A
Use HTTP requests to query the available metadata server at the http://metadata.google.internal/ endpoint with the Metadata-Flavor: Google header.
B
In the Google Cloud console, navigate to the Project Dashboard and gather configuration details. Navigate to the Cloud Run “Variables & Secrets” tab, and add the desired environment variables in Key:Value format.
C
In the Google Cloud console, navigate to the Project Dashboard and gather configuration details. Write the application configuration information to Cloud Run's in-memory container filesystem.
D
Make an API call to the Cloud Asset Inventory API from the application and format the request to include instance metadata.
No comments yet.