Question

Difficulty: MediumDeploying Serverless Applications with Cloud Run and Cloud Functions

A solutions team is building an automated file processing solution on Google Cloud. Every time a JPEG file is created in a Cloud Storage bucket named `raw-image-uploads`, a lightweight Node.js routine must run to create a thumbnail. The team chooses Cloud Functions (2nd gen) because of its native Eventarc integration and event-driven execution model. Which `gcloud` CLI command should the team run to correctly deploy this function triggered by file uploads?

  1. gcloud functions deploy thumbnail-generator --gen2 --runtime=nodejs20 --entry-point=createThumbnail --source=. --trigger-event-filters="type=google.cloud.storage.object.v1.finalized" --trigger-event-filters="bucket=raw-image-uploads" --region=us-central1Answer
  2. B
    gcloud run deploy thumbnail-generator --source=. --port=8080 --trigger-bucket=gs://raw-image-uploads --region=us-central1
  3. C
    gcloud functions deploy thumbnail-generator --gen2 --runtime=nodejs20 --entry-point=createThumbnail --source=. --trigger-http --allow-unauthenticated --region=us-central1
  4. D
    gcloud functions deploy thumbnail-generator --gen2 --runtime=nodejs20 --entry-point=createThumbnail --source=. --trigger-event-filters="type=google.cloud.storage.object.v1.finalized" --project=my-org-root-policy

Answer

The command starting with `gcloud functions deploy thumbnail-generator --gen2` using `--trigger-event-filters` for `google.cloud.storage.object.v1.finalized` and specifying the `bucket=raw-image-uploads` filter is correct.
Deploying a 2nd gen Cloud Function triggered by Cloud Storage requires using the `gcloud functions deploy` command with the `--gen2` flag and Eventarc event filters. The filter `type=google.cloud.storage.object.v1.finalized` combined with `bucket=raw-image-uploads` ensures that the function is invoked whenever a new file is uploaded to the specified bucket.

Step-by-Step Solution

1
Identify the target deployment model and runtime engine.
The requirement specifies Cloud Functions (2nd gen) for event-driven processing of Cloud Storage events.
Cloud Functions 2nd gen relies on Eventarc event filters for background bucket events.
2
Determine the mandatory gcloud flags for Cloud Storage event triggers in 2nd gen functions.
Use `--gen2` with `--trigger-event-filters="type=google.cloud.storage.object.v1.finalized"` and `--trigger-event-filters="bucket=BUCKET_NAME"`.
This registers the Eventarc trigger to invoke the function automatically upon object creation.

Key Concept

Deploying Cloud Functions (2nd gen) with Cloud Storage Eventarc triggers
Rate this question