0
0
GCPcloud~10 mins

Why serverless functions matter in GCP - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to deploy a simple serverless function on Google Cloud Functions.

GCP
gcloud functions deploy myFunction --runtime [1] --trigger-http --allow-unauthenticated
Drag options to blanks, or click blank then click option'
Apython39
Bnodejs14
Cgo113
Druby27
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a runtime not supported by Google Cloud Functions.
Using an outdated or incorrect runtime version.
2fill in blank
medium

Complete the code to specify the entry point function name for your serverless function.

GCP
gcloud functions deploy myFunction --runtime python39 --entry-point [1] --trigger-http --allow-unauthenticated
Drag options to blanks, or click blank then click option'
Ahandler
Bmain
Cfunction
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not exist in the code.
Leaving out the entry point parameter.
3fill in blank
hard

Fix the error in the function code to correctly handle an HTTP request in Python.

GCP
from flask import Response
def handler(request):
    return [1]('Hello, world!')
Drag options to blanks, or click blank then click option'
Astr
Bprint
CResponse
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a plain string instead of an HTTP response.
Using print instead of return.
4fill in blank
hard

Fill both blanks to configure environment variables and memory allocation for the serverless function.

GCP
gcloud functions deploy myFunction --runtime python39 --trigger-http --set-env-vars [1]=prod --memory [2]
Drag options to blanks, or click blank then click option'
AENVIRONMENT
BREGION
C256MB
D512MB
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect environment variable names.
Omitting memory units or using invalid values.
5fill in blank
hard

Fill all three blanks to create a serverless function that logs a message and returns a JSON response.

GCP
import json
import logging

def handler(request):
    logging.[1]('Function called')
    response = {'message': 'Success'}
    return json.[2](response), [3]
Drag options to blanks, or click blank then click option'
Ainfo
Bdumps
C200
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong logging levels like error instead of info.
Returning a Python dict instead of a JSON string.
Omitting the HTTP status code.