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?
- 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"Cevap
- Bgcloud run deploy image-processor --image=gcr.io/my-project/image-processor --trigger-bucket=user-uploads-bucket --entry-point=processImage
- Cgcloud functions deploy image-processor --gen2 --runtime=nodejs20 --entry-point=processImage --port=8080 --set-env-vars=PORT=8080
- Dgcloud functions deploy image-processor --gen2 --runtime=nodejs20 --entry-point=processImage --trigger-topic=user-uploads-bucket --role=roles/owner
Cevap
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.
Adım Adım Çözüm
Anahtar Kavram
Deploying 2nd Gen Cloud Functions with Cloud Storage Eventarc Triggers
Tahmini Süre:1m 30s