Professional Cloud Developer · Domain 3: Configuring cloud-native applications for deployment · 24% of the exam
Task 3.1: Deploying applications to Cloud Run.
Deploying from source, invoking services through Eventarc and Pub/Sub triggers, configuring event receivers, and versioning, exposing and securing APIs with Apigee.
Study it
Deploying to Cloud Run from source, Eventarc and Pub/Sub triggers and event receivers
Lesson coming
Versioning, exposing and securing APIs with Apigee
Try each one before opening the answer. Every option is explained, with the Google Cloud documentation page that proves it.
Question 1 · choose 1
The Cloud Run service api has the environment variables DB_HOST, LOG_LEVEL
and FEATURE_FLAGS. A new CI job deploys it from source with:
gcloud run deploy api --source . --region=europe-west1 \
--set-env-vars=RELEASE=$BUILD_TAG
After the first run, the new revision crashes because DB_HOST is missing.
Which change keeps the existing variables while setting RELEASE on each
deployment?
AAdd --clear-env-vars before --set-env-vars in the same command
BDeploy with gcloud run services replace and a service.yaml that sets only RELEASE
CMove RELEASE into the Dockerfile with an ENV instruction and keep --set-env-vars
DReplace --set-env-vars with --update-env-vars=RELEASE=$BUILD_TAG
Show the answer and why
AAdd --clear-env-vars before --set-env-vars in the same command
Incorrect
Clearing removes the remaining variables too, the opposite of what is needed.
BDeploy with gcloud run services replace and a service.yaml that sets only RELEASE
Incorrect
Replacing the service with a YAML file that lists only RELEASE leaves out the other variables.
CMove RELEASE into the Dockerfile with an ENV instruction and keep --set-env-vars
Incorrect
--set-env-vars still deletes every variable not in its list.
DReplace --set-env-vars with --update-env-vars=RELEASE=$BUILD_TAG
Correct
Updating changes or adds variables without deleting those already set.
On Cloud Run, --set-env-vars is a destructive action: it deletes previously set environment variables that aren't in the new list. --update-env-vars is the non-destructive approach that changes or adds variables but keeps the others. Environment variables are bound to a revision, so each deployment carries the full set.
A Node.js web app without a Dockerfile is deployed to Cloud Run with gcloud run deploy --source, so it is built with Google Cloud's buildpacks. The app serves its CSS and JavaScript files with the framework's default Last-Modified and ETag headers. After each release, some users keep getting old versions of those files from their browser caches. What does Google recommend for this situation?
APin a specific buildpacks builder image in place of the latest builder
BDisable the ETag and Last-Modified headers in the application
CRaise the minimum number of instances so that new files are served at once
DTurn on session affinity so that each browser reaches one instance
Show the answer and why
APin a specific buildpacks builder image in place of the latest builder
Incorrect
Setting source file dates to Jan 1, 1980 is the default buildpacks behaviour for reproducible builds, not a quirk of one builder.
BDisable the ETag and Last-Modified headers in the application
Correct
Buildpacks set the files' Last Modified Date to Jan 1, 1980, so headers derived from it no longer change between releases.
CRaise the minimum number of instances so that new files are served at once
Incorrect
Instance count has no effect on what browsers keep in their caches.
DTurn on session affinity so that each browser reaches one instance
Incorrect
Affinity changes which instance serves a client, not the file dates in the headers.
Deploying from source with Google Cloud's buildpacks sets the Last Modified Date of source files to Jan 1, 1980, the default behaviour that supports reproducible builds. Depending on the framework, this can affect browser-side caching of static files, and Google recommends disabling the ETag and Last-Modified HTTP headers in the application if it is affected.
A team creates an Eventarc trigger for uploads to a bucket in us-central1
of the same project, with a dedicated trigger service account that has the
Eventarc Event Receiver role and can invoke the target service:
gcloud eventarc triggers create uploads-trigger \
--location=us-central1 \
--destination-run-service=ingest \
--destination-run-region=us-central1 \
--event-filters="type=google.cloud.storage.object.v1.finalized" \
--event-filters="bucket=acme-uploads" \
--service-account=trigger-sa@acme.iam.gserviceaccount.com
What else must be in place before this trigger can deliver events?
APub/Sub Subscriber on the project for trigger-sa
BStorage Object Viewer on the bucket for the Eventarc service agent
CPub/Sub Publisher on the project for the Cloud Storage service agent
DCloud Run Developer on the ingest service for trigger-sa
Show the answer and why
APub/Sub Subscriber on the project for trigger-sa
Incorrect
The documented setup gives the trigger's account the Event Receiver role only; the missing grant is on the Cloud Storage side.
BStorage Object Viewer on the bucket for the Eventarc service agent
Incorrect
Direct Cloud Storage events need the publishing permission of the Cloud Storage service agent, not object reads.
CPub/Sub Publisher on the project for the Cloud Storage service agent
Correct
The page says to grant this role before creating a trigger for direct events from Cloud Storage.
DCloud Run Developer on the ingest service for trigger-sa
Incorrect
The trigger's account receives events and invokes the service; deploying the service isn't part of delivery.
For direct events from Cloud Storage, the Eventarc quickstart grants the trigger's service account the Eventarc Event Receiver role and, before the trigger is created, grants the Pub/Sub Publisher role to the Cloud Storage service agent of the project, found with gcloud storage service-agent.
A Cloud Run service must react each time a new object is written to a bucket. A developer proposes an Eventarc trigger on the Cloud Audit Logs event for storage.objects.create. A colleague notes that Eventarc also supports a direct event for the same change. What does the Eventarc documentation recommend?
AThe audit log trigger, because audit log events cover more services
BA trigger that filters for the direct Cloud Storage event on the bucket
CBoth triggers on the same service, so that no upload is missed
DA Cloud Scheduler job that lists new objects every minute
Show the answer and why
AThe audit log trigger, because audit log events cover more services
Incorrect
Coverage of other services doesn't matter here; for an event that both kinds support, direct events are recommended.
BA trigger that filters for the direct Cloud Storage event on the bucket
Correct
When both direct and audit log events are supported, Eventarc recommends the direct event, which has several advantages.
CBoth triggers on the same service, so that no upload is missed
Incorrect
Two triggers for one change send the service two events per upload; the recommendation is the direct event alone.
DA Cloud Scheduler job that lists new objects every minute
Incorrect
Polling replaces events with a schedule; Eventarc already routes the direct event.
Eventarc triggers can filter for Cloud Audit Logs events, produced when an audit log entry is written, or for direct events, triggered by an unmediated change such as an update to an object in a Cloud Storage bucket. If both kinds are supported for the event to route, Eventarc recommends creating a trigger that filters for the direct event.
A Cloud Run function loads each uploaded file into a database:
@functions_framework.cloud_event
def ingest(cloud_event):
data = cloud_event.data
load_rows(data["bucket"], data["name"]) # raises if the DB is busy
During development, its Eventarc trigger was created with:
gcloud eventarc triggers create ingest-trigger \
--location=us-central1 \
--destination-run-service=ingest \
--destination-run-region=us-central1 \
--event-filters="type=google.cloud.storage.object.v1.finalized" \
--event-filters="bucket=acme-drop" \
--service-account=trigger-sa@acme.iam.gserviceaccount.com \
--max-retry-attempts=1
In production, files that arrive while the database is briefly busy are
never loaded, and each shows a single failed execution. What should the team
change?
ACatch the exception in ingest and return normally, so that the event is scheduled for another attempt
BSet --max-retry-attempts=5 on the trigger so that each event gets five delivery attempts
CConfigure a retry setting on the function's Cloud Run service so that failed executions are retried
DCreate the trigger again without --max-retry-attempts and keep the handler idempotent
Show the answer and why
ACatch the exception in ingest and return normally, so that the event is scheduled for another attempt
Incorrect
Further attempts come only from the trigger's retry policy, and this trigger allows a single delivery attempt.
BSet --max-retry-attempts=5 on the trigger so that each event gets five delivery attempts
Incorrect
For an Eventarc trigger, the only valid value of --max-retry-attempts is 1.
CConfigure a retry setting on the function's Cloud Run service so that failed executions are retried
Incorrect
Retries of event-driven functions are configured on the Eventarc trigger that invokes them, not on the function itself.
DCreate the trigger again without --max-retry-attempts and keep the handler idempotent
Correct
--max-retry-attempts=1 asks for a single delivery attempt with no retries; without the flag, the standard retry behavior applies.
For Cloud Run destinations, including Cloud Run functions, an Eventarc trigger can make a single delivery attempt with no retries: that is what --max-retry-attempts does on gcloud eventarc triggers create, and 1 is its only valid value there. If the flag is omitted, the standard retry behavior applies, so an event whose function execution fails is delivered again. The retries property is set on the trigger, not on the function. Because delivery is at least once, a handler that is retried should be idempotent. Google recommends disabling retries while developing and enabling them in production.
A push subscription with its default settings sends video jobs to a Cloud Run service. The handler transcodes each video before it returns 200, which takes between 1 and 4 minutes, well within the service's request timeout. Every job is transcoded two or more times. Which change stops the repeated deliveries?
AExtend each message's acknowledgment deadline from the handler while it works
BRaise the subscription's acknowledgment deadline to 20 minutes
CRaise the subscription's acknowledgment deadline to 300 seconds
DKeep the settings, because Pub/Sub waits for the push response however long the handler takes
Show the answer and why
AExtend each message's acknowledgment deadline from the handler while it works
Incorrect
The deadline of individual messages received from push subscriptions can't be modified.
BRaise the subscription's acknowledgment deadline to 20 minutes
Incorrect
The acknowledgment deadline can be set to at most 600 seconds.
CRaise the subscription's acknowledgment deadline to 300 seconds
Correct
The default is 10 seconds; at 300 seconds, within the 600-second maximum, the 200 arrives before the deadline expires.
DKeep the settings, because Pub/Sub waits for the push response however long the handler takes
Incorrect
When the acknowledgment deadline expires, Pub/Sub resends the message.
For push subscriptions, Pub/Sub resends a message when its acknowledgment deadline expires, and the deadline of individual push messages can't be modified. The subscription's acknowledgment deadline option defaults to 10 seconds and can be set from 10 to 600 seconds, so a handler that needs up to 4 minutes needs a deadline longer than that, such as 300 seconds.
An Apigee organization has one environment group, prod-group, with the host name api.example.com and three environments: cart-prod, catalog-prod and partners-prod. A new set of proxies for partners is deployed only in partners-prod. The partners must get their own host name that reaches the partner proxies and nothing in the other two environments. What should the team do?
ACreate another environment group that holds only partners-prod and give it the host name partners.example.com
BAdd the host name partners.example.com directly to the environment partners-prod and leave prod-group as it is
CAdd partners.example.com to prod-group as a second host name
DRename partners-prod to partners so that its name appears in the URL
Show the answer and why
ACreate another environment group that holds only partners-prod and give it the host name partners.example.com
Correct
A host name on a group with only partners-prod can route requests only to proxies in that environment.
BAdd the host name partners.example.com directly to the environment partners-prod and leave prod-group as it is
Incorrect
Host names are defined on environment groups, not on individual environments.
CAdd partners.example.com to prod-group as a second host name
Incorrect
A host name of prod-group routes to proxies in all three of its environments.
DRename partners-prod to partners so that its name appears in the URL
Incorrect
Environment and group names don't affect the URL of the API endpoint.
In Apigee, host names are defined on environment groups, and a host name can route requests to proxies in any environment of its group. To restrict access to the proxies of one environment, create another environment group that contains only that environment; a host name of that group reaches only that environment. Environment and group names aren't exposed in the URL.
A Cloud Run service needs the environment variable ALLOWED_ORIGINS with the value https://a.example.com,https://b.example.com. Passing it as --set-env-vars ALLOWED_ORIGINS=https://a.example.com,https://b.example.com doesn't produce that value. How should the variable be passed?
AWrap the value in single quotes inside the flag
BRepeat ALLOWED_ORIGINS in two separate --set-env-vars flags, one for each origin
^@^ makes @ the delimiter between variables, so the commas stay inside the value.
The comma separates environment variables in the --set-env-vars flag. When a value contains commas, specify a different delimiter character, for example @, by starting the argument with ^@^; variables are then separated by @ and commas stay in the values.
A push subscription delivers messages to a Cloud Run service that will be down for maintenance for two hours. The team wants Pub/Sub to stop sending requests to the endpoint during that time without losing messages, and to resume afterwards. What does the Pub/Sub documentation say to do?
ADelete the subscription and create it again after the maintenance
BSet the push endpoint to an empty value and leave the subscription type as push
CChange the subscription to pull, then set the endpoint URL again later
DSet the service's minimum instances to zero for the two hours
Show the answer and why
ADelete the subscription and create it again after the maintenance
Incorrect
Deleting the subscription stops delivery permanently.
BSet the push endpoint to an empty value and leave the subscription type as push
Incorrect
The documented pause is a change of the subscription to pull.
CChange the subscription to pull, then set the endpoint URL again later
Correct
Changing to pull temporarily stops push requests, and setting a valid endpoint URL resumes push delivery.
DSet the service's minimum instances to zero for the two hours
Incorrect
Pub/Sub keeps sending requests to the endpoint; only a change to the subscription stops them.
To temporarily stop Pub/Sub from sending requests to a push endpoint, change the subscription to pull; the changeover can take several minutes. To resume push delivery, set the URL to a valid endpoint again. Deleting the subscription stops delivery permanently.
An Apigee API proxy's proxy endpoint has two conditional flows, listed in this order: all-posts, whose condition is true for every POST request, and purge, whose condition is true for POST requests to /purge and which holds a VerifyAPIKey policy. A client sends a POST request to /purge. Which flows run?
ABoth conditional flows, in the order in which they are listed
BOnly all-posts, so the VerifyAPIKey policy in purge doesn't run
COnly purge, because its condition is the more specific one
DNeither, because a request that matches two conditions skips both flows
Show the answer and why
ABoth conditional flows, in the order in which they are listed
Incorrect
Only one conditional flow is executed per segment, even when several conditions are true.
BOnly all-posts, so the VerifyAPIKey policy in purge doesn't run
Correct
The first flow whose condition evaluates to true is the one that runs.
COnly purge, because its condition is the more specific one
Incorrect
Apigee picks the first true condition in the listed order, not the most specific one.
DNeither, because a request that matches two conditions skips both flows
Incorrect
A request that matches conditions still runs one flow: the first one that matches.
Between the PreFlow and the PostFlow of an endpoint, Apigee executes only one conditional flow per segment: the first flow whose condition evaluates to true. Here all-posts matches first, so the VerifyAPIKey policy in purge never runs for this request.