This page contains code samples for Cloud Functions. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.
Cached library
HTTP Cloud Function that uses a cached client library instance to reduce the number of connections required per function invocation.
View in documentation
View in documentation
Cloud Storage Hello World
Shows a Storage Cloud Function sample.
Cloud Storage integration tests
Demonstrates how to integration test a function triggered by Cloud Storage.
View in documentation
Cloud Storage unit tests
Demonstrates how to unit test a function triggered by Cloud Storage.
View in documentation
Execution after HTTP response
Example of code that won't execute after an HTTP response is sent.
View in documentation
Global versus function scope
Creates a heavy object only once per function instance, and shares it across all function invocations reaching the given instance.
View in documentation
View in documentation
- Create and deploy a HTTP Cloud Function by using Go
- Create and deploy a HTTP Cloud Function by using Node.js
- Create and deploy a HTTP Cloud Function by using PHP
- Create and deploy a HTTP Cloud Function by using Python
- Create and deploy a HTTP Cloud Function by using Ruby
- HTTP Functions
- HTTP Triggers
- Specifying dependencies in Node.js
- Testing HTTP Functions
- Tips & Tricks
- Writing Cloud Functions
HTTP Hello World - Get
Function that prints "Hello world!" in response to a GET request.
View in documentation
OCR tutorial step 1 - Process image
Demonstrates how to upload image files to Cloud Storage, and extract and translate text from the images by using the Vision API and Translation API.
View in documentation
OCR tutorial step 2 - Detect text
Demonstrates how to upload image files to Cloud Storage, and extract and translate text from the images by using the Vision API and Translation API.
View in documentation
OCR tutorial step 3 - Translate text
Demonstrates how to upload image files to Cloud Storage, and extract and translate text from the images by using the Vision API and Translation API.
View in documentation
OCR tutorial step 4 - Save result
Demonstrates how to upload image files to Cloud Storage, and extract and translate text from the images by using the Vision API and Translation API.
View in documentation
View in documentation
Process a Cloud Audit Logging log entry
Shows how to process an Audit Log entry.
View in documentation
Pub/Sub Hello World
Shows a Pub/Sub Cloud Function sample.
View in documentation
- .NET Languages
- Background Functions
- Calling Cloud Functions Directly
- Cloud Pub/Sub Tutorial
- CloudEvent Functions
- Getting Started Tutorial: Cloud Functions (2nd gen)
- Google Cloud Pub/Sub Triggers
- JVM Languages
- Local Development
- Testing Background Functions
- Testing Event-Driven Functions
- Writing Cloud Functions
Pub/Sub integration tests
Demonstrates how to integration test a function triggered by Pub/Sub.
View in documentation
Pub/Sub Subscribe to a Topic
Demonstrates how to subscribe to a topic and parse the received event with Pub/Sub from Cloud Functions.
View in documentation
Pub/Sub system tests
Demonstrates how to system test a function triggered by Pub/Sub.
View in documentation
Pub/Sub unit tests
Demonstrates how to unit test a function triggered by Pub/Sub.
View in documentation
Use HTTP connection pooling
Shows how to recycle HTTP connections using HTTP connection pools.
View in documentation