Cannot destroy Firebase connections making hot Lambda fail due to 'Firebase App name '[DEFAULT]' already exists'

点点圈 提交于 2019-12-11 02:25:55

问题


Been trying every approach I can think of for hours.

Basically I'm running an AWS Lambda function which does some work to my Firebase app in both a client and server role.

Being on Lambda, I need to be able to reverse the firebase.initializeApp(config) and firebase.initializeApp(config, 'server'). I've tried firebase.app('server').delete() but that doesn't seem to work.

Thanks in advance for any help.

To clarify, I can't just use the existing connection because the config may change.


回答1:


Calls to initializeApp take an optional app name. If the app name is not specified, the name [DEFAULT] is used.

To uninitialize an app, you need to call delete on the app instance. The app instance is returned by the initializeApp call or can be obtained using the app function.

That is, you can initialize and uninitialize an app like this:

app = firebase.initializeApp(configuration);
app.delete();

Or like this:

firebase.initializeApp(configuration);
firebase.app('[DEFAULT]').delete();

Note that the delete function returns a promise that resolves when the app deletion is complete.




回答2:


Alternatively, you can also just initialise the Firebase instance outside of your handler function and pass it down. This prevents it from getting invoked multiple times.

Lambda likes to spin up one instance of a function, but continuously call its function handler, meaning code outside the handler is only executed once.

This can be applied to most anything that only lets you have one instance going.




回答3:


initializeApp returns the initialized app. You can do :

const app = firebase.initializeApp(config);
//...
await app.delete();


来源:https://stackoverflow.com/questions/39436072/cannot-destroy-firebase-connections-making-hot-lambda-fail-due-to-firebase-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!