Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

O. Functions

Hadi Tavakoli edited this page Jul 8, 2019 · 1 revision

Cloud Functions for Firebase

Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.

Functions can be written in JavaScript or TypeScript.

Key capabilities

Capability Description
Integrates the Firebase platform The functions you write can respond to events generated by these other Firebase and Google Cloud features: Cloud Firestore Triggers, Realtime Database Triggers, Remote Config Triggers, Firebase Authentication Triggers, Google Analytics for Firebase Triggers, Crashlytics Triggers, Cloud Storage Triggers, Cloud Pub/Sub Triggers, HTTP Triggers. Integrate across Firebase features using the Admin SDK together with Cloud Functions, and integrate with third-party services by writing your own webhooks. Cloud Functions minimizes boilerplate code, making it easier to use Firebase and Google Cloud inside your function.
Zero maintenance Deploy your JavaScript or TypeScript code to our servers with one command from the command line. After that, Firebase automatically scales up computing resources to match the usage patterns of your users. You never worry about credentials, server configuration, provisioning new servers, or decommissioning old ones.
Keeps your logic private and secure In many cases, developers prefer to control application logic on the server to avoid tampering on the client side. Also, sometimes it's not desirable to allow that code to be reverse engineered. Cloud Functions is fully insulated from the client, so you can be sure it is private and always does exactly what you want.

How does it work?

After you write and deploy a function, Google's servers begin to manage the function immediately. You can fire the function directly with an HTTP request, or, in the case of background functions, Google's servers will listen for events and run the function when it is triggered.

As the load increases or decreases, Google responds by rapidly scaling the number of virtual server instances needed to run your function. Each function runs in isolation, in its own environment with its own configuration.

Lifecycle of a background function

  1. The developer writes code for a new function, selecting an event provider (such as Realtime Database), and defining the conditions under which the function should execute.
  2. The developer deploys the function, and Firebase connects it to the selected event provider.
  3. When the event provider generates an event that matches the function's conditions, the code is invoked.
  4. If the function is busy handling many events, Google creates more instances to handle work faster. If the function is idle, instances are cleaned up.
  5. When the developer updates the function by deploying updated code, all instances for the old version are cleaned up and replaced by new instances.
  6. When a developer deletes the function, all instances are cleaned up, and the connection between the function and the event provider is removed.

In addition to listening for events with a background function, you can call functions directly with an HTTP request or a call from the client (AdobeAIR app).

Implementation path

Step Description
  1. Set up Cloud Functions | Install the Firebase CLI and initialize Cloud Functions in your Firebase project.
  2. Write functions | Write JavaScript code (or TypeScript code to transpile at deployment) to handle events from Firebase services, Google Cloud services, or other event providers.
  3. Test functions | Use the local emulator to test your functions.
  4. Deploy and monitor | Deploy your functions using the Firebase CLI. You can use the Firebase console to view and search through your logs.

Get started with Firebase Functions in AdobeAIR


DISCRIMINATION: Firebase SDKs are developed by Google and they own every copyright to the Firebase "native" projects. However, we have used their "compiled" native SDKs to develop the ActionScript API to be used in AdobeAIR mobile projects. Moreover, as far as the documentations, we have copied and when needed has modified the Google documents so it will fit the needs of AdobeAIR community. If you wish to see the original documentations in Android/iOS, visit here. But if you are interested to do things in AdobeAIR, then you are in the right place.

Introduction to Firebase ANEs collection for Adobe Air apps


Get Started with Firebase Core in AIR

  1. Prerequisites
  2. Add Firebase to your app
  3. Add the Firebase SDK
  4. Init Firebase Core
  5. Available ANEs
  6. Managing Firebase iid

Get Started with Analytics

  1. Add Analytics ANE
  2. Init Analytics ANE
  3. Log Events
  4. Set User Properties

Get Started with Crashlytics

  1. Add Crashlytics ANE
  2. Test Your Implementation
  3. Customize Crash Reports
  4. Upload .dSYM for iOS apps

Get Started with DynamicLinks

  1. Add DynamicLinks ANE
  2. Init DynamicLinks ANE
  3. Create DynamicLinks
  4. Receive DynamicLinks
  5. View Analytics

Get Started with Authentication

  1. Add Authentication
  2. Init Authentication
  3. Manage Users
  4. Phone Number
  5. Custom Auth
  6. Anonymous Auth
  7. State in Email Actions
  8. Email Link Authentication

Get Started with FCM + OneSignal

  1. Add FCM ANE
  2. Init FCM ANE
  3. Send Your 1st Message
  4. Send Msg to Topics
  5. Understanding FCM Messages
  6. init OneSignal

Get Started with Firestore

  1. Add Firestore
  2. Init Firestore
  3. Add Data
  4. Transactions & Batches
  5. Delete Data
  6. Manage the Console
  7. Get Data
  8. Get Realtime Updates
  9. Simple and Compound
  10. Order and Limit Data
  11. Paginate Data
  12. Manage Indexes
  13. Secure Data
  14. Offline Data
  15. Where to Go From Here

Get Started with Realtime Database

  1. Add Realtime Database
  2. Init Realtime Database
  3. Structure Your Database
  4. Save Data
  5. Retrieve Data
  6. Enable Offline Capabilities

Get Started with Remote Config

  1. Parameters and Conditions
  2. Add Remote Config
  3. Init Remote Config

Get Started with Performance

  1. Add Performance ANE
  2. Init & Start Monitoring

Get Started with Storage

  1. Add Storage ANE
  2. Init Storage ANE
  3. Upload Files to Storage
  4. Download Files to Air
  5. Use File Metadata
  6. Delete Files

Get Started with Functions

  1. Write & Deploy Functions
  2. Add Functions ANE
  3. Init Functions
Clone this wiki locally