Complete the code to specify the trigger type for a Cloud Function.
gcloud functions deploy myFunction --gen2 --trigger-[1] my-topic --runtime python312The --trigger-pubsub flag sets the function to trigger on Pub/Sub messages.
Complete the code to specify the Pub/Sub topic name for the trigger.
gcloud functions deploy myFunction --gen2 --trigger-pubsub [1] --runtime python312The full resource name projects/my-project/topics/my-topic specifies the Pub/Sub topic.
Fix the error in the function code to correctly decode the Pub/Sub message data.
def my_function(event, context): import base64 message = base64.b64decode(event['message']['[1]']).decode('utf-8') print(f"Received message: {message}")
The Pub/Sub message data is in the event['message']['data'] field of the event.
Fill both blanks to create a Cloud Function that logs the message ID and publish time.
def my_function(event, context): message_id = event['message']['[1]'] publish_time = event['message']['[2]'] print(f"Message ID: {message_id}, Published at: {publish_time}")
The message ID is accessed with event['message']['messageId'] and the publish time with event['message']['publishTime'].
Fill all three blanks to deploy a Cloud Function with a Pub/Sub trigger, specifying the runtime and entry point.
gcloud functions deploy [1] --gen2 --runtime [2] --trigger-pubsub [3] --entry-point my_function
The function name is myFunction, the runtime is python312, and the Pub/Sub topic is specified with the full path.