Using Firebase Admin SDK with Lambda Function

Per the recommendation of other posts in this community I’ve also tried deploying the function without the use of dotenv, and also used some regex text replacement for the private key because it has \n escaped characters by default.

And that was the secret combo to get this working! Downside is I have to have a different method for local env variables, but good news is I’m finally working with serverless functions!

For anyone else who runs into this problem, make sure the private key you’re passing into the service credential object is replacing these characters:

const serviceCredential = {
  // ...
  private_key: process.env.FB_PRIVATE_KEY.replace(/\\n/g, '\n'),
  // ...
}