모든 Cloud Run 코드 샘플

This page contains code samples for Cloud Run. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.

Authenticate service-to-service requests

Services hosted on Google Cloud with access to the Compute Metadata Server are able to generate an OAuth authentication token using the service account identity associated with the service. This token can be used to authenticate the service as a permitted invoker of a Cloud Run service.

View in documentation

Generate a diagram with the dot tool from the graphviz package

Use a customized Dockerfile to configure system packages whose command-line utilities are used as part of serving HTTP requests.

View in documentation

Handler for Pub/Sub messages

Service to handle messages delivered by a Cloud Pub/Sub Push subscription.

Hello World service

Create a simple Hello World application, package it into a container image, upload the container image to Container Registry, and then deploy the container image to Cloud Run.

View in documentation

Lazy variable initialization

Demonstrate the use of lazy initialization of values for cases where memory allocation and response latency impacting operations are not commonly needed by the Cloud Run service.

View in documentation

Open a gRPC connection to a service

Function to create a new gRPC connection.

View in documentation

Pub/Sub handler to process Cloud Storage events

This tutorial demonstrates using Cloud Run, Cloud Vision API, and ImageMagick to detect and blur offensive images uploaded to a Cloud Storage bucket.

Retrieve image from Cloud Storage to blur and then upload to a storage bucket

This tutorial demonstrates using Cloud Run, Cloud Vision API, and ImageMagick to detect and blur offensive images uploaded to a Cloud Storage bucket.

Send gRPC requests with authentication

Sends a request with an authorization header using a gRPC connection.

View in documentation

Send gRPC requests without authentication

Sends a request without authentication using a gRPC connection.

View in documentation

Service for local troubleshooting

Sample demonstrating an easily broken service that is difficult to troubleshoot without careful investigation, and an improved version of the code.

Sign in via Google

Client side code for signing in via the Google provider using the Firebase SDK

Use Cloud Vision API to determine if image is safe

This tutorial demonstrates using Cloud Run, Cloud Vision API, and ImageMagick to detect and blur offensive images uploaded to a Cloud Storage bucket.

Using global scoped variables

Demonstrate how to minimize the memory footprint of reusable variables by leveraging global scope.

View in documentation

Write structured logs

Writes structured log entries with request log correlation using common libraries.

View in documentation