0
0
GCPcloud~30 mins

Pub/Sub with Cloud Functions integration in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Pub/Sub with Cloud Functions integration
📖 Scenario: You are building a simple notification system on Google Cloud Platform. When a message is published to a Pub/Sub topic, a Cloud Function should automatically trigger and process the message.
🎯 Goal: Create a Pub/Sub topic, configure a Cloud Function that triggers on messages published to this topic, and set the function to log the message data.
📋 What You'll Learn
Create a Pub/Sub topic named notifications-topic.
Create a Cloud Function named processNotification triggered by notifications-topic.
The Cloud Function should log the message data received from Pub/Sub.
💡 Why This Matters
🌍 Real World
Pub/Sub with Cloud Functions is commonly used to build event-driven systems where messages trigger automated processing, such as notifications, data pipelines, or alerts.
💼 Career
Understanding how to integrate Pub/Sub with Cloud Functions is essential for cloud developers and engineers working on scalable, serverless architectures on Google Cloud Platform.
Progress0 / 4 steps
1
Create the Pub/Sub topic
Create a Pub/Sub topic named notifications-topic using the gcloud command-line tool.
GCP
Need a hint?

Use the gcloud pubsub topics create command followed by the topic name.

2
Create the Cloud Function configuration
Create a Cloud Function named processNotification that triggers on the Pub/Sub topic notifications-topic. Use the runtime python39 and specify the entry point as process_notification.
GCP
Need a hint?

Use gcloud functions deploy with the --trigger-topic flag and specify the runtime and entry point.

3
Write the Cloud Function code
Write the Python function process_notification that takes event and context parameters and logs the Pub/Sub message data decoded as UTF-8.
GCP
Need a hint?

Use base64.b64decode to decode the message data and print to log it.

4
Finalize Cloud Function deployment
Update the Cloud Function deployment to include the source code file named main.py containing the process_notification function.
GCP
Need a hint?

Use the --source . flag to specify the current directory containing main.py.