Google Professional Cloud Developer Question 332
Select 3Google Cloud PlatformYou are deploying a Python-based REST API to Google Cloud Functions. The API relies on a third-party library that is not part of the Python standard library. What steps should you take to ensure the deployment is successful?
- A
Include a requirements.txt file with the necessary library dependencies.
- B
Use the gcloud CLI to specify the runtime as Python during deployment.
- C
Manually install the third-party library on your local machine before deploying.
- D
Package the third-party library as a .zip file and upload it separately to Google Cloud Storage.
- E
Ensure your entry point matches the function name specified in your main Python script.
Show answer and explanation
Correct answers: A, B, E
Explanation
When deploying Python-based applications to Google Cloud Functions, you need to include a requirements.txt file to specify dependencies, ensure the correct runtime is used, and define an entry point that matches the function name. These steps ensure your application is deployed correctly and functions as expected in a serverless environment.
- A. Correct.
Correct. A
requirements.txtfile is required when deploying Python applications to Google Cloud Functions, as it ensures all dependencies are installed during deployment. - B. Correct.
Correct. Explicitly specifying the runtime (e.g., Python 3.9) ensures that Google Cloud Functions uses the appropriate environment for your code.
- C. Incorrect.
Incorrect. Installing the library on your local machine does not automatically make it available in the serverless environment.
- D. Incorrect.
Incorrect. Packaging and uploading the library as a .zip file is unnecessary because Google Cloud Functions installs dependencies listed in the
requirements.txtfile automatically. - E. Correct.
Correct. The entry point in your deployment must match the function name in your script, as this is how Google Cloud Functions identifies the function to trigger.