firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Error when deploying to AWS Lambda (Node 6.10.3)

Open shauntrennery opened this issue 9 years ago • 32 comments

I'm getting a "Unable to import module" error when deploying v5.3.0 or above to AWS Lambda. The error log is cryptic but it does contain reference to "firebase-admin/node_modules/grpc/src/node/src/grpc_extension.js:30:15"

All works as expected when downgrading to v5.2.1.

shauntrennery avatar Oct 10 '17 08:10 shauntrennery

One possible cause of this problem with gRPC is running the installation on a different platform than you are deploying on. The important things to consider are Node version (the major version has to match), operating system (Linux vs Windows vs Mac), and architecture (32 bit vs 64 bit vs ARM). If you can't easily do that, you can force it to install the right binary by passing additional arguments to npm install: --target=<node version> --target_arch=x64 --target_platform=linux

murgatroid99 avatar Oct 17 '17 16:10 murgatroid99

@jpamorgan There's no fix for running Firestore on Lambda. Firestore uses gRPC, and gRPC only supports node.js via native code. At this point we recommend dockerizing your deployments. We're working on a write-up on how to do this, but I can't promise a timeline.

wilhuff avatar Oct 17 '17 19:10 wilhuff

Just same error like the ones from @shauntrennery (attached below). Does anyone noticed the blog post from https://aws.amazon.com/de/blogs/compute/nodejs-packages-in-lambda/ , have no time yet for a closer look, but this may give a hint.

Native modules are similarly installed and deployed, but you’ll need to build them against the Amazon Linux libraries. You’ll need to either ensure that the libraries and their transitive dependencies are statically compiled or use rpath-style linking; we’ll do it the static way in this post, and demonstrate use of rpath in a subsequent post. (Note that many, but not all, libraries can be statically linked this way.)

Unable to import module 'firebaseServerAuth': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/node_modules/grpc/src/node/src/grpc_extension.js:30:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

PutziSan avatar Oct 17 '17 21:10 PutziSan

I am currently working on a guide for how to do this (as @wilhuff said). However the meat of it is that you need to use docker to install your dependencies.

If you rm -rf node_modules and then use this command:

docker run --rm -it -v "$PWD":/worker -w /worker node:6.10.3 npm i --production --silent

Your dependencies will be installed in a way that makes them compatible with Lambda's node 6.10 runtime. I have successfully written data to Cloud Firestore from AWS Lambda.

samtstern avatar Oct 18 '17 22:10 samtstern

Here's a full writeup: https://medium.com/@samstern_58566/how-to-use-cloud-firestore-on-aws-lambda-4bf6d3a473d9

samtstern avatar Oct 19 '17 17:10 samtstern

I've published an RC at https://storage.googleapis.com/firebase-admin-node/firebase-admin-5.4.3-rc0.tgz

@shauntrennery @srameshr can you run some tests with it on AWS and let us know if that resolves your issue? This should allow you to at least use the latest Admin SDK without bumping into any gRPC module loading problems.

hiranya911 avatar Oct 20 '17 19:10 hiranya911

This is extremely annoying issue - you guys really should have thought about this before deploying this... nothing is more annoying that everythign breaking when doing an update and no notice anywhere that it may occur.. When you start depending on C++ modules in Node.js its a pretty strong indicator that things are going to break for a fairly large percentage of people.

I can understand if I were actually adding the firestore somewhere but I am not...

On that note... @hiranya911 yes your given pacakge does appear to resolve the issue so thank you.

bradennapier avatar Oct 23 '17 08:10 bradennapier

@hiranya911 I did try it. It broke again. I cant do it again because I dont have a dev version of EB stalk. My production server runs there. As of now I will stick with 5.3.0 without any updates.

srameshr avatar Oct 23 '17 08:10 srameshr

@bradennapier glad the new package is working for you. Please be respectful when discussing issues on Github, we try to be honest about our mistakes and fix them when we break something.

samtstern avatar Oct 23 '17 15:10 samtstern

Thanks everybody who helped test this fix. It is now released: https://firebase.google.com/support/release-notes/admin/node#5.4.3

hiranya911 avatar Oct 24 '17 17:10 hiranya911

I'm running 5.7.3 and this issue still persists... any idea?

andresmijares avatar Jan 19 '19 02:01 andresmijares

Having this issue... 5 years later. Is firebase-admin not compatible with lambda's serverless environment?

ryanhaticus avatar May 07 '22 04:05 ryanhaticus