The buzz is booming around serverless functions, also known as cloud functions. A sure sign of this? The big players, like Google and AWS, have entered the arena.
Google has introduced its own serverless function on GCP. Since Google joined the Functions as a Service (FaaS) world, the new serverless execution option offers many benefits. Let’s take a look.
What are Google Cloud Functions?
The execution environment of Google Cloud Functions enables serverless programming on top of Google Cloud Platforms. The introduction of Google Cloud Functions, which are scalable, pay-as-you-go FaaS, offers many options in a simpler environment, making it easier for developers to run and scale your code in the cloud. The functions can be coded in Python, node.js, and Go—so developers likely won’t need to learn anything new to use them.
Google Cloud Functions easily solves the many worries you may traditionally experience, like:
- Multiple services needing extra managing
- Predicting traffic to each service
- Risk of service going down during a spike or load
- Overpaying for unused capacity
You may be thinking “Why is Google Cloud Functions important?” Well, there are a number of key features we will explain, below, that makes using Google Cloud easier, faster, and seamless of the developer.
Types of Google Cloud Functions
There are two types of Google Cloud Functions:
- HTTP functions
- Background functions
HTTP Functions
The HTTP functions are primarily used when you want to invoke your function via an HTTP(S) request. This type of function can be used for webhooks and creating APIs. The Cloud Function abstracts away the information infrastructure, so you do not need much code.
Executing your Google Cloud Function has to signal your function in order to actually run. This is known as a trigger. The HTTP trigger comes from a request sent to your function or can be an event from Google Pub/Sub events, stack driver, or a Firebase Event.
The following command shows how to call the function and pass it as a parameter using curl:
curl -X POST HTTP_TRIGGER_ENDPOINT -H "Content-Type:application/json”'{"name":"Jane"}'where HTTP_TRIGGER_ENDPOINT()
(Source)
Background Functions
Background functions are triggered when specific cloud events occur. For example, when a file is uploaded into the cloud, a function can automatically run to process the upload. These background functions currently respond to:
- Pub/Sub events
- Cloud storage
- Firebase events
This creates multiple use cases such as:
- Transforming data
- Processing IoT messages
- Watching project logs and reacting to specified changes within the infrastructure