Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Labs

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.

Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon Aug 21, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. 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.

  2. Challenge

    Configure Pub/Sub

    1. Create a service account with the Cloud Run Invoker role.
    2. Create a Cloud Pub/Sub topic.
    3. 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.

  3. Challenge

    Test the Service

    1. Publish some test messages to your Pub/Sub topic.
    2. 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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans