Google Firebase Functions vs AWS Lambda, A shallow comparison

Madura Pradeep
ShoutOUT Blog
Published in
3 min readDec 19, 2017

A few days back, I got the chance to get hands-on experience on Firebase functions and I thought of sharing with you all what I learned. I hope to compare it with AWS Lambda as I am familiar with that ☺️ Also note that Firebase functions is still in beta.

First of all, it wasn’t that hard to learn and deploy Firebase function as it’s documentation (We know how hard it is to read AWS documentation ☺️) is pretty much okay for me. So kudos for the Firebase documentation.

Before doing anything else, you have to install firebase tools. Without that, you can’t upload your function into Firebase. On the other hand, in AWS Lambda, you don’t need any additional tools to install and can directly upload and test your function in their console itself. Therefore, the initial learning curve is minimum in Lambda.

After going through the initial learning curve, it’s really convenient to use Firebase tools to manage the project — easy to create and deploy. For Lambda too, you can experience the same (or higher) level of convenience by installing tools like Node Lambda, Lambda Local or a toolkit like Serverless.

For writing Firebase function, you have to import their library first and implement the methods as required. Given below is how you can write a simple HTTP endpoint in Firebase. The disadvantage I came across here is that Firebase function library itself is about 2.1MB in size. It’s quite heavy and I have to check how that effect the loading time of the function.

Eg: Firebase functions creating a HTTP endpoint

const functions = require(‘firebase-functions’);

exports.addMessage = functions.https.onRequest((req, res) => {

res.send(“ok”);

});

Once you deploy the function, you will get an HTTP endpoint to call that.

On the other hand, you can simply create a function and create an AWS API Gateway endpoint to expose HTTP endpoint for the function in Lambda. You can do all of this from the Lambda console itself.

Eg: Lambda function

exports.handler = (event, context, callback) => {

callback(null,“send”);

};

You can see function execution logs in the dashboard in both Firebase and Lambda.

If you are using Firebase as your database, then it’s really easy to access your database if your function is also under the same project. It’s just a matter of importing the Firebase Admin library. You don’t have to configure any security rules or anything for accessing the database (Of course you can limit it if you need).

Eg: Access Firebase Firestore from Firebase functions

const admin = require(‘firebase-admin’);

let db = admin.firestore();

let docRef = db.collection(“users”);

Lambda also provides the same convenience if you are using a Database like DynamoDB, except that you have to create an IAM role to allow access for Lambda function to DynamoDB. BTW it’s not that hard. You can do it by creating a function from Lambda console by choosing a blue-print or using a toolkit like Serverless.

The other thing Lambda lovers like most is execution types and triggers it provides. You can execute Lambda function as an event asynchronously so that the function executor can exit without waiting. Don’t worry, you can do the same by using pub-sub trigger functions in Firebase.

You can subscribe a function to a topic, and that function will execute when any function publishes a message to that topic.

Eg: Firebase sample pubsub function
module.exports = functions.pubsub.topic(‘Say_Hello’).onPublish(event => {

});

Firebase provides following triggers to trigger a function.

Regarding the pricing, as I could find on some blogs, AWS Lambda is the winner. But if you use HTTP endpoints in Lambda, you have to use API Gateway and the pricing of API gateway also will come into the picture.

For the final thoughts, Firebase functions is still in the beta whereas Lambda has played quite long in the market. So, obviously the resources and maturity level of Lambda will be higher, compared to the Firebase Functions. Also, Lambda supports a number of different programming languages as well. What will match to your project is depend on what is your project and how the project is going to deploy.

--

--