Skip to content

Professional Cloud Developer · Domain 4: Integrating applications with Google Cloud services · 21% of the exam

Task 4.2: Consuming Google Cloud APIs.

Enabling services, calling APIs through client libraries, REST, gRPC and the API Explorer with batching, partial responses, pagination, caching and exponential backoff, and calling APIs as a service account.

Study it

  • Calling Google Cloud APIs: client libraries, REST and gRPC, batching, partial responses, pagination, caching, exponential backoff and service accounts

    Partly covered by: Designing a REST API, Caching

Sample questions

Try each one before opening the answer. Every option is explained, with the Google Cloud documentation page that proves it.

Question 1 · choose 1

A cleanup script disables every API that a sandbox project no longer seems to use. Its list includes the Cloud Run Admin API and the Cloud Storage API. The project still has three Cloud Run services and two buckets with test data. What happens when the script disables these APIs?

  1. AThe Cloud Run services are deleted, while the buckets and their data stay
  2. BBoth stay as they are and come back when the APIs are enabled again
  3. CThe buckets are emptied, while the Cloud Run services stop serving but remain
  4. DThe script fails, because enabled APIs can't be disabled while resources exist
Show the answer and why
  • AThe Cloud Run services are deleted, while the buckets and their data stay

    Correct

    Disabling the Cloud Run API deletes its resources, and disabling the Cloud Storage API doesn't delete stored data.

  • BBoth stay as they are and come back when the APIs are enabled again

    Incorrect

    Disabling the Cloud Run API deletes the resources associated with Cloud Run.

  • CThe buckets are emptied, while the Cloud Run services stop serving but remain

    Incorrect

    Data stays when the Cloud Storage API is disabled, and Cloud Run resources are deleted.

  • DThe script fails, because enabled APIs can't be disabled while resources exist

    Incorrect

    An API can be disabled at any time; only dependent enabled services block it.

Disabling a service's API has different effects per service. For services such as Cloud Storage and BigQuery, disabling the API doesn't delete data, and storage keeps being billed. When the Cloud Run API is disabled, the resources associated with Cloud Run are deleted. Take inventory of the resources before disabling an API; a disable request fails only when other enabled services depend on the service, unless dependent services are disabled too.

Question 2 · choose 1

A worker's calls to the Cloud Storage JSON API failed as follows: 1. objects.get (download a report) -> 503 2. objects.patch metadata, no precondition -> 503 3. bucket ACL patch (add a reader) -> 503 4. objects.list (prefix reports/) -> 429 The worker retries with truncated exponential backoff and jitter. Which failed calls should it retry automatically?

  1. AAll four calls, since 503 and 429 both mark transient problems
  2. BCalls 1, 2 and 4, since only ACL changes are risky to repeat
  3. CCalls 1 and 4 only
  4. DCalls 2 and 3 only, since reads can be repeated later by the user
Show the answer and why
  • AAll four calls, since 503 and 429 both mark transient problems

    Incorrect

    A retryable response isn't enough; the patches aren't safe to repeat as sent.

  • BCalls 1, 2 and 4, since only ACL changes are risky to repeat

    Incorrect

    A metadata patch without a metageneration or ETag precondition isn't idempotent either.

  • CCalls 1 and 4 only

    Correct

    Gets and lists are always idempotent, a patch without a precondition isn't, and ACL patches never are.

  • DCalls 2 and 3 only, since reads can be repeated later by the user

    Incorrect

    The writes are the calls that aren't safe to retry as sent.

Whether to retry depends on the response and on idempotency. 408, 429 and 5xx responses indicate transient problems. Get and list requests are always idempotent; updates and patches of objects are idempotent only with an IfMetagenerationMatch or ETag precondition; ACL changes are never idempotent. Safe retries should use truncated exponential backoff with jitter.

Question 3 · choose 1

A small Cloud Run job written in shell must call the Cloud Resource Manager REST API as the job's attached service account, without client libraries and without the gcloud CLI in the image. How should the script get the credential for its requests?

  1. AGet an access token from the metadata server, with the Metadata-Flavor: Google header, as a Bearer token
  2. BCreate an API key and send it in the x-goog-api-key header
  3. CSet the x-goog-user-project header to the job's project
  4. DShip a key file of the job's service account in the image and sign each request with a token made from it
Show the answer and why
  • AGet an access token from the metadata server, with the Metadata-Flavor: Google header, as a Bearer token

    Correct

    On Cloud Run, the metadata server returns an access token for the attached service account.

  • BCreate an API key and send it in the x-goog-api-key header

    Incorrect

    API keys work only with APIs that accept them and don't identify the service account.

  • CSet the x-goog-user-project header to the job's project

    Incorrect

    That header sets the quota project for user credentials; it isn't a credential.

  • DShip a key file of the job's service account in the image and sign each request with a token made from it

    Incorrect

    The attached account's token is available from the metadata server, so a long-lived key adds risk for nothing.

For REST requests in environments with a metadata server, such as Compute Engine, Cloud Run, Cloud Run functions, GKE and Cloud Build, an application can query the metadata server for an access token of the attached service account, sending the Metadata-Flavor: Google header, and then pass the token in the Authorization header. API keys work only with APIs that accept them, and the quota project header applies to user credentials.

Question 4 · choose 1

A script sends one Compute Engine API batch request that first creates a disk and then attaches that disk to an existing VM. Now and then the attach call in the batch fails because the disk doesn't exist yet. What should the script do?

  1. AList the create call first in the batch, since the calls run in the order listed
  2. BSplit the batch so that each inner call goes to a different API
  3. CAdd more calls to the batch so that it takes longer to process
  4. DSend the create call alone, wait for its result, then send the attach call
Show the answer and why
  • AList the create call first in the batch, since the calls run in the order listed

    Incorrect

    The server might perform the calls in any order, whatever the order in the request.

  • BSplit the batch so that each inner call goes to a different API

    Incorrect

    All inner requests of a batch must go to the same API.

  • CAdd more calls to the batch so that it takes longer to process

    Incorrect

    The size of a batch doesn't give its calls an order.

  • DSend the create call alone, wait for its result, then send the attach call

    Correct

    To make two calls happen in order, the first must be sent by itself before the second.

A batch request groups several calls to the same API into one HTTP request, and the response holds one part per call in the order of the requests. However, the server might perform the calls in any order, so a call that depends on another can't share its batch; send the first call by itself and wait for the response.

Google Cloud documentation

Question 5 · choose 1

An internal support console calls Google Cloud REST APIs while support engineers work on customer cases. Auditors want the case number behind each call to be recorded in the audit logging of that call. What should the console add to each request?

  1. AThe case number as the quotaUser value of each request
  2. BThe case number in the X-Goog-Api-Client header
  3. CThe case number in the X-Goog-Request-Reason header
  4. DThe case number in the x-goog-request-params header
Show the answer and why
  • AThe case number as the quotaUser value of each request

    Incorrect

    quotaUser is a pseudo user identifier for charging per-user quotas.

  • BThe case number in the X-Goog-Api-Client header

    Incorrect

    That header identifies the API client with name and version strings.

  • CThe case number in the X-Goog-Request-Reason header

    Correct

    That header holds a reason for making the request, intended to be recorded in audit logging, such as a support-case ticket number.

  • DThe case number in the x-goog-request-params header

    Incorrect

    That header passes extra, API-specific parameters for gRPC requests, such as routing information.

Google's API platform defines system parameters that work across REST and gRPC APIs. X-Goog-Request-Reason contains a reason for making the request, which is intended to be recorded in audit logging; the page's example is a support-case ticket number. quotaUser is used for charging per-user quotas, X-Goog-Api-Client identifies the API client, and x-goog-request-params carries additional parameters for gRPC requests.

Google Cloud documentation

Question 6 · choose 1

A multi-tenant service accepts a service account key JSON from each customer and uses it to call Google Cloud APIs in the customer's project. It loads the uploaded JSON with the authentication library's generic credentials loader. What does Google require before such configurations are used?

  1. ANothing, because keys created in the Google Cloud console are always safe to load
  2. BConvert each key into an API key before calling the APIs
  3. CStore the keys in Secret Manager, which validates them on upload
  4. DValidate them, for example by loading them with the loader specific to service account keys
Show the answer and why
  • ANothing, because keys created in the Google Cloud console are always safe to load

    Incorrect

    Configurations from an external source must be validated before use.

  • BConvert each key into an API key before calling the APIs

    Incorrect

    API keys work only with APIs that accept them and don't replace the customer's service account.

  • CStore the keys in Secret Manager, which validates them on upload

    Incorrect

    Storing the file doesn't validate its contents.

  • DValidate them, for example by loading them with the loader specific to service account keys

    Correct

    A type-specific loader parses only the fields of a service account key, which don't expose vulnerabilities.

Some credential configurations include endpoints and file paths that the authentication libraries use to get a token. When an application accepts credential configurations from an external source, such as a customer, it must validate them before use; if it accepts only service account keys, it should use the credential loader specific to service account keys.

Practice domain 4 →Practice all domains →