Google Professional Cloud Developer Question 347
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud and want to trigger a Cloud Function when a new file is uploaded to a specific Cloud Storage bucket. What steps should you take to correctly configure the trigger for this use case?
- A
Create a Cloud Function, set the trigger type to 'Cloud Storage', and specify the bucket name and event type as 'google.storage.object.finalize'.
- B
Create a Cloud Function, set the trigger type to 'Pub/Sub', and specify the topic that receives notifications from the Cloud Storage bucket.
- C
Create a Cloud Function, set the trigger type to 'Firestore', and configure the bucket to send object upload events to Firestore.
- D
Create a Cloud Function, set the trigger type to 'HTTP', and configure the bucket to send HTTP requests to the function on object creation.
Show answer and explanation
Correct answer: A
Explanation
To trigger a Cloud Function when a new file is uploaded to a Cloud Storage bucket, you should use the 'Cloud Storage' trigger type and specify the event type 'google.storage.object.finalize'. This is the most direct and efficient way to handle this use case without extra configuration steps or intermediate services.
- A. Correct.
This is the correct approach. By setting the trigger type to 'Cloud Storage', you can directly connect the Cloud Function to the bucket and specify the 'google.storage.object.finalize' event for new file uploads.
- B. Incorrect.
This is incorrect. Using Pub/Sub requires additional configuration to publish events from the bucket to a topic, which is unnecessary for this scenario since Cloud Storage triggers are directly supported.
- C. Incorrect.
This is incorrect. Firestore is not relevant for Cloud Storage object events, and there is no built-in mechanism to send bucket events to Firestore.
- D. Incorrect.
This is incorrect. HTTP triggers require manual configuration of HTTP endpoints and are not directly integrated with Cloud Storage events.