Google Cloud Functions is a compute solution for developers to create single-purpose, stand-alone functions that respond to cloud events without the need to manage a server or runtime environment, this is why Cloud Functions are considered serverless architecture.
Cloud Functions for Firebase provides a way to extend the behavior of Firebase and integrate Firebase features through the addition of server-side code. It is a joint product between the Google Cloud Platform team and the Firebase team.
There are 2 distinct types of Cloud Functions:
I assume you have a prior experience using Firebase.
gcloud auth application-default login
When complete, your project structure should look similar to this:
. ├── .firebaserc #Hidden file that helps you quickly switch projects | #using 'firebase use' ├── firebase.json #Describes properties for your project └── functions #Directory containing all your functions code ├── index.js #main source file for your Cloud Functions code | └── package.json #npm package file describing your Cloud Functions #code
2. Let’s add our first Cloud Function.
This function passes a text value and inserts it into the database under the path
3. Let’s add a background function that modifies our data
makeUppercase() function executes when Cloud Firestore is written to.
ref.set defines the document to listen to.
The Firebase Local Emulator Suite allows us to build and test apps on our local machine instead of deploying to a project.
*If you receive an error “
Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
gcloud auth application-default login*
Using the emulator suite, we can locally test our functions:
$ firebase deploy --only functions
Here we see our deployed functions with additional details.
Google Cloud Functions is a lightweight compute solution for developers to create single-purpose, stand-alone functions that respond to cloud events without the need to manage a server or runtime environment. Be sure to check out some function examples below!
Cassandra.Link is a knowledge base that we created for all things Apache Cassandra. Our goal with Cassandra.Link was to not only fill the gap of Planet Cassandra, but to bring the Cassandra community together. Feel free to reach out if you wish to collaborate with us on this project in any capacity.
We are a technology company that specializes in building business platforms. If you have any questions about the tools discussed in this post or about any of our services, feel free to send us an email!