Google Professional Cloud Developer Question 348
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud and need to trigger a Cloud Function whenever a new file is uploaded to a specific Cloud Storage bucket. The function processes the file and stores the result in Firestore. Which trigger should you use to invoke the function?
- A
Cloud Pub/Sub Topic Trigger
- B
Cloud Storage Object Finalize Trigger
- C
HTTP Trigger
- D
Firestore Document Write Trigger
Show answer and explanation
Correct answer: B
Explanation
To trigger a Cloud Function when a new file is uploaded to a Cloud Storage bucket, you should use the Cloud Storage Object Finalize Trigger. This event is emitted when a new object is successfully created in the bucket. Other triggers, such as HTTP or Firestore triggers, are not applicable for this use case.
- A. Incorrect.
Cloud Pub/Sub Topic Trigger is used for event-driven architectures but is not a direct trigger for changes in Cloud Storage objects. It would require additional configuration to publish to a topic on a file upload.
- B. Correct.
Cloud Storage Object Finalize Trigger is the correct trigger for invoking a function when a new file is uploaded to a Cloud Storage bucket. This event is fired when the file is successfully written and finalized.
- C. Incorrect.
HTTP Trigger is used to invoke Cloud Functions via HTTP requests. It is not suitable for events like file uploads in Cloud Storage.
- D. Incorrect.
Firestore Document Write Trigger is used for changes to Firestore documents and is not related to Cloud Storage events.