Google Professional Cloud Developer Question 345
Single answerGoogle Cloud PlatformYou are developing a serverless application using Google Cloud Functions. The application needs to automatically process new images uploaded to a Cloud Storage bucket by resizing them. Which trigger option should you use to invoke the function when a file is uploaded to the bucket?
- A
Cloud Pub/Sub trigger
- B
Cloud Storage trigger
- C
HTTP trigger
- D
Cloud Scheduler trigger
Show answer and explanation
Correct answer: B
Explanation
The Cloud Storage trigger is the best choice for this scenario because it directly listens for events, such as file uploads to a Cloud Storage bucket, and automatically invokes the function. This eliminates the need for additional components like Pub/Sub or HTTP triggers, making the implementation simpler and more efficient.
- A. Incorrect.
A Cloud Pub/Sub trigger is used for messaging between services. While you could publish a message to a topic when a file is uploaded and then trigger a function, it is not the most direct or efficient approach for this use case.
- B. Correct.
A Cloud Storage trigger is specifically designed to invoke Cloud Functions when events occur in a Cloud Storage bucket, such as file uploads. This is the correct option for this scenario.
- C. Incorrect.
An HTTP trigger is used to invoke a function via HTTP requests. It would require additional setup (e.g., creating a trigger for uploads) and is not the best choice for processing events directly from Cloud Storage.
- D. Incorrect.
A Cloud Scheduler trigger is for scheduling tasks to run at specific times or intervals. It cannot be used to trigger functions based on Cloud Storage events like file uploads.