CodeAlchemy

Jotting one man's journey through software development, programming, and technology


Project maintained by pablogarciaprado Hosted on GitHub Pages — Theme by mattgraham

◀️ Home

Introduction

Cloud Run functions is a fully managed serverless execution environment on Google Cloud for you to build, deploy, and run functions. It is a scalable functions-as-a-service platform, where there is no need to provision any infrastructure or manage individual servers.

Cloud Run is a managed compute platform that lets you run containers directly on top of Google’s scalable infrastructure. You can deploy code written in any programming language on Cloud Run if you can build a container image from it.

A cloud function is simple code that you write that serves a single piece of functionality. It’s triggered by an event that is generated by cloud infrastructure and other services. Cloud functions execute in a fully managed serverless environment. Cloud Run functions provides a connective layer of logic that lets you write code to connect and extend cloud services. To set up and use Cloud Run functions, you:

  1. Develop the function code or logic in one of the supported programming languages.
  2. Deploy the function: You can deploy the function using the Google Cloud console or the gcloud CLI.
  3. Set up a trigger for the function to execute in response to HTTP requests or supported cloud events.

Features

Benefits

Two types of Cloud Run functions

Supported language runtimes and regions

The language runtime that you choose and the type of function that you want to write determine the structure of your code and function implementation. For Cloud Run functions to locate your function definition, each language runtime has specific requirements for structuring your source code.

Basic Directory Structure Function Entry Point

Deploying Cloud Run functions

The deployment process takes your function source code and configuration settings and builds a runnable image. Cloud Run functions automatically manages the image in order to handle requests to your function.

Deplyment Basics

A user deploying Cloud Run functions must have the Cloud Functions Developer IAM role or a role that includes the same permissions. To deploy Cloud Run functions, a user must also be assigned the Service Account User IAM role on the Cloud Run functions runtime service account.

Deployment Process

Build Process

When you deploy your function’s source code to Cloud Run functions, that source is stored in a Cloud Storage bucket. Cloud Build is a service that executes builds on Google Cloud infrastructure. Cloud Build automatically builds your function source code into a container image, and pushes that image to Artifact Registry. Cloud Run functions then accesses this image when it needs to run the container to execute your function. The process of building the image is entirely automatic and requires no direct input from you.

Cloud Run functions uses Artifact Registry to store the images built from your function source code. Artifact Registry is a service that is used to store and manage software artifacts in private repositories, including container images, and language packages. Artifact Registry integrates with Cloud Build to store the packages from your builds.