Complete the code to deploy a simple serverless function on Google Cloud Functions.
gcloud functions deploy myFunction --runtime [1] --trigger-http --allow-unauthenticatedThe correct runtime for deploying a Python 3.9 serverless function on Google Cloud Functions is python39.
Complete the code to specify the entry point function name for your serverless function.
gcloud functions deploy myFunction --runtime python39 --entry-point [1] --trigger-http --allow-unauthenticatedThe entry point is the name of the function in your code that Cloud Functions will execute. handler is commonly used as the function name.
Fix the error in the function code to correctly handle an HTTP request in Python.
from flask import Response def handler(request): return [1]('Hello, world!')
Google Cloud Functions expects an HTTP response object. Using flask.Response correctly returns an HTTP response.
Fill both blanks to configure environment variables and memory allocation for the serverless function.
gcloud functions deploy myFunction --runtime python39 --trigger-http --set-env-vars [1]=prod --memory [2]
Setting ENVIRONMENT=prod defines the environment variable. Allocating 256MB memory is a common minimal memory setting for serverless functions.
Fill all three blanks to create a serverless function that logs a message and returns a JSON response.
import json import logging def handler(request): logging.[1]('Function called') response = {'message': 'Success'} return json.[2](response), [3]
logging.info logs an informational message. json.dumps converts the dictionary to a JSON string. 200 is the HTTP status code for success.