Question

Difficulty: MediumDeploying Serverless Applications with Cloud Run and Cloud Functions

A developer needs to deploy an event-driven Node.js microservice to Google Cloud Functions (2nd gen) that executes whenever a new image file is created in a Cloud Storage bucket named `user-uploads-bucket`. The code entry point is `processImage`. Which `gcloud` command should be executed to successfully deploy this serverless application?

  1. gcloud functions deploy image-processor --gen2 --runtime=nodejs20 --entry-point=processImage --trigger-event-filters="type=google.cloud.storage.object.v1.finalized" --trigger-event-filters="bucket=user-uploads-bucket"Answer
  2. B
    gcloud run deploy image-processor --image=gcr.io/my-project/image-processor --trigger-bucket=user-uploads-bucket --entry-point=processImage
  3. C
    gcloud functions deploy image-processor --gen2 --runtime=nodejs20 --entry-point=processImage --port=8080 --set-env-vars=PORT=8080
  4. D
    gcloud functions deploy image-processor --gen2 --runtime=nodejs20 --entry-point=processImage --trigger-topic=user-uploads-bucket --role=roles/owner

Answer

Execute `gcloud functions deploy image-processor --gen2 --runtime=nodejs20 --entry-point=processImage --trigger-event-filters="type=google.cloud.storage.object.v1.finalized" --trigger-event-filters="bucket=user-uploads-bucket"`.
The command starting with `gcloud functions deploy` specifying `--gen2` and `--trigger-event-filters="type=google.cloud.storage.object.v1.finalized"` with `--trigger-event-filters="bucket=user-uploads-bucket"` is correct because Cloud Functions (2nd gen) relies on Eventarc to route Cloud Storage events. Providing both the event type and bucket name in the event filters configures the trigger properly.

Step-by-Step Solution

1
Identify the target serverless platform and generation
The requirement specifies deploying a Cloud Function (2nd gen) using source code with entry point `processImage`.
Cloud Functions 2nd gen is built on top of Cloud Run and Eventarc.
2
Determine the event trigger requirements
The trigger is a Cloud Storage object creation event (`google.cloud.storage.object.v1.finalized`) on the `user-uploads-bucket` bucket.
2nd gen Cloud Functions require Eventarc flags specified via `--trigger-event-filters`.
3
Construct the exact `gcloud functions deploy` command
Combine `--gen2`, `--runtime=nodejs20`, `--entry-point=processImage`, and the two required `--trigger-event-filters` flags.
This matches Google Cloud's CLI specification for deploying 2nd gen event-driven functions.

Key Concept

Deploying 2nd Gen Cloud Functions with Cloud Storage Eventarc Triggers
Estimated Time:1m 30s
Rate this question