Introduction to Cloud Functions
This course will demonstrate how you can create complex workflows by using existing Google Cloud Products and connecting them via simple, single-purpose functions.
- Understand the main features of Cloud Functions
- Learn how to deploy a function
- Learn how to set up triggers
- Understand the differences between Gen 1 and Gen 2
- Cloud Architects
- GCP Developers
- Anyone preparing for a Google Cloud certification
- Access to a GCP account
Google Cloud Platform includes a wide range of services. So while you can use it to build something custom, most of the time your needs are already covered by an existing product. Google has proven, scalable solutions that are ready to use today.
Now sometimes you will be able to accomplish your goals using a single service. However, there will be other times where you will require multiple services. And often, you will need some way to control and orchestrate how these services interact with each other.
Let me give you an example. Say a company wants to allow its customers to upload images of documents. These documents need to be parsed for any relevant information. And then that information needs to be stored in a database. Now all three of these steps can be handled using a combination of Cloud Storage, Document AI, and Cloud SQL.
Cloud Storage would be perfect for storing the images. Document AI is great at identifying text in images. And Cloud SQL is optimized for storing text data. However, these three services do not automatically work together. You are going to have to add some “glue code” to create your desired workflow.
This is what Google Cloud Functions was designed for. Cloud Functions allow you to trigger small bits of code based upon events. So in this example, you could add a trigger to Cloud Storage that fires whenever an image is uploaded. Now this trigger would execute a function that would pass the uploaded image to Document AI for parsing. You could also add a second trigger to copy the output from Document AI and save to a Cloud SQL database. So, you won’t need to build and maintain a giant, monolithic application that does everything. Instead, you can create a bunch of small, lightweight functions.
Now this technique offers many advantages. First, it’s going to require much less code. This means quicker development times and faster testing. You will be able to get more work done with less effort and less risk.
Second, it’s going to give you a lot more flexibility. With just a handful of functions, you can create some pretty complex workflows. And the best part is that these workflows can have multiple entry points, exits, and even branching. And all of this is going to happen server-side. So your users won’t need to download any updates. You can add big new features without disrupting production.
Third, it’s going to make things cheaper and much easier to scale. Cloud Functions are serverless. That means you don’t have to provision any costly VMs or Kubernetes clusters. You are only charged when a function is running. So instead of having expensive applications running all the time, you have several small, cheap functions that only run in tiny bursts. And, if one part of your workflow is slow, then you only need to scale up that particular section. You are not going to have to scale the entire workflow.
Google Cloud Functions allows you to build powerful, event-driven systems with only a minimal amount of code. You can use it to connect multiple Google Cloud products together or even third-party services. Now if you are already familiar with Cloud Run, this might sound pretty similar. And I will say that the two services do have quite a bit of overlap. However, there are a few important differences:
First, Cloud Run is more powerful. It is designed for running containers, so you can write in any language and include any libraries you want. But creating a fully working container requires more work and more code. Cloud Functions have limited support for languages and libraries but generally requires much less code.
Second, Cloud Run has much better scaling. Each container can handle multiple concurrent requests. In Cloud Function, each instance can only handle a single request at a time.
Third, Cloud Run has more flexibility. It offers higher amounts of CPU and memory. In addition, Cloud Run supports multiple revisions and traffic splitting. Cloud Functions currently lacks these features.
So basically, if you are already familiar with Cloud Run, then you can think of Cloud Functions as being less complex. It can do similar things, but it sacrifices flexibility for simplicity. Cloud Functions are really optimized for treating cloud services like building blocks. You can connect them together to build something much more complex and powerful.
Daniel began his career as a Software Engineer, focusing mostly on web and mobile development. After twenty years of dealing with insufficient training and fragmented documentation, he decided to use his extensive experience to help the next generation of engineers.
Daniel has spent his most recent years designing and running technical classes for both Amazon and Microsoft. Today at Cloud Academy, he is working on building out an extensive Google Cloud training library.
When he isn’t working or tinkering in his home lab, Daniel enjoys BBQing, target shooting, and watching classic movies.