Chapter 2. Cloud Functions

Google Cloud Functions is a serverless compute platform that allows you to run your code based on triggers such as uploading files to Cloud Storage or adding/deleting/updating Firestore documents, or trigger your functions directly from the web. Google Cloud provides two types of Cloud Functions: HTTP functions and background functions. You invoke HTTP functions from standard HTTP requests. You use background functions to trigger your function based on an event such as files being uploaded to Cloud Storage, receiving a message in Pub/Sub, updating a Firestore collection, or basing it on a schedule.

Google Cloud Functions abstract the compute infrastructure and allow you to focus on your code. You don’t have to worry about patching operating systems or provisioning resources. Cloud functions scale automatically; they can scale from a single invocation to millions without intervention from the developer. In this chapter, we will present a range of recipes, from introductory recipes you can use to send emails or respond to SMS messages to advanced recipes that show you how to integrate CI/CD into your development workflow and integrate with Cloud Endpoints for API management.

Google Cloud Functions can be written in Node.js, Python, Go, Java, .NET, Ruby, and PHP programming languages. In this chapter, you will be using Node.js. All code samples for this chapter are in this book’s GitHub repository. You can follow along and copy the code for each recipe ...

Get Google Cloud Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.