Google Professional Cloud Developer Question 343
Select 3Google Cloud PlatformYou are developing a backend system on Google Cloud and need to process uploaded images in real-time. The images are uploaded to a Cloud Storage bucket, and you want to invoke a function to process the images whenever a new file is uploaded. Which of the following steps are required to achieve this?
- A
Create a Cloud Function with a Cloud Storage trigger and specify the bucket name.
- B
Set the Cloud Function to be triggered by the 'google.storage.object.finalize' event.
- C
Manually poll the bucket for new files using a custom script and invoke the Cloud Function using an HTTP trigger.
- D
Enable the Cloud Storage API and grant the required permissions to the Cloud Function's service account.
- E
Use Pub/Sub to subscribe to bucket notifications and invoke the Cloud Function when a new message is received.
Show answer and explanation
Correct answers: A, B, D
Explanation
To process new files uploaded to a Cloud Storage bucket, you can use a Cloud Function with a Cloud Storage trigger. This approach removes the need for manual polling or intermediate Pub/Sub configurations. The trigger should be set to respond to the 'google.storage.object.finalize' event, which is fired when a new object is successfully created. Additionally, proper permissions need to be set up for the Cloud Function's service account to access the bucket.
- A. Correct.
Correct. To automatically invoke a Cloud Function when a file is uploaded, you need to create a Cloud Function with a Cloud Storage trigger and specify the bucket name.
- B. Correct.
Correct. The 'google.storage.object.finalize' event is triggered when a new object is successfully created in the bucket, which is the appropriate event for processing new uploads.
- C. Incorrect.
Incorrect. Manually polling for new files is not an efficient or recommended solution in this scenario when Cloud Storage triggers are available.
- D. Correct.
Correct. The Cloud Storage API must be enabled, and the Cloud Function's service account needs the appropriate permissions (e.g., 'roles/storage.objectViewer') to access the bucket and its contents.
- E. Incorrect.
Incorrect. While Pub/Sub can be used for bucket notifications, it is not required in this case since Cloud Functions can directly subscribe to Cloud Storage events.