- Lab
- A Cloud Guru
Triggering Cloud Run with Pub/Sub
In this lab, we will create a Cloud Run service that renders some 3D text and stores the image in a Cloud Storage bucket. The Cloud Run service will not be publicly available. Instead, we will create a Cloud Pub/Sub topic with an authenticated push subscription to send messages to our rendering service. You should be familiar with the GCP console, Cloud Shell, and service accounts to perform this hands-on lab. Some familiarity with Cloud Pub/Sub would be helpful but is not essential.
Path Info
Table of Contents
-
Challenge
Deploy the Rendering Service
The code for the render service can be found at this GitHub repo:
https://github.com/ACloudGuru-Resources/content-google-cloudrun-deepdive-render
Note: Before you create the container, you will need to create a Cloud Storage bucket to hold rendered images. Then, you will need to update the code of the render service with the name of your bucket (line 35 of
function.py
).Build the container and push it to Google Container Registry, replacing
<YOUR_PROJECT>
with your project ID:gcloud builds submit --tag gcr.io/<YOUR_PROJECT>/render .
The deployed service should not allow unauthenticated invocations.
-
Challenge
Configure Pub/Sub
- Create a service account with the Cloud Run Invoker role.
- Create a Cloud Pub/Sub topic.
- Create a subscription for the topic:
- The subscription should be Push.
- It should use the endpoint of the
render
service. - It should use the service account you just created.
Note: When you enable authentication for the Push subscription, Pub/Sub will prompt you to add the
iam.serviceAccountTokenCreator
role and then reset the Add subscription form. This appears to be a normal (if somewhat quirky) behavior of the Cloud Console. Just re-enter the information to create the subscription, and it will work. -
Challenge
Test the Service
- Publish some test messages to your Pub/Sub topic.
- View the rendered images in the Cloud Storage bucket.
Images may take a minute or two to render before you can see them in the bucket. If you have any problems, check the logs of your Cloud Run service.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.