[英]Firestore not working with AWS Lambda
I have initialized firebase inside my AWS lambda function using the Node.js 8.10 runtime. 我已使用Node.js 8.10运行时在AWS lambda函数中初始化了Firebase 。 This is the relevant code:
这是相关代码:
'use strict';
const https = require('https'),
firebase = require('firebase-admin'),
admin = require('firebase-admin');
//Initialize firebase
let serviceAccount = require('./one-deed-6b407-firebase-adminsdk-ha9ud-3c7ddb5906.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
let db = admin.firestore();
Later in the code I created a firestore database: 稍后在代码中,我创建了一个Firestore数据库:
exports.handler = (event, context, callback) => {
var docRef = db.collection('users').doc('alovelace');
var setAda = docRef.set({
first: 'Ada',
last: 'Lovelace',
born: 1815
});
}
However, the document in question was not added even though the code works properly when I run I locally. 但是,即使我在本地运行时代码可以正常工作,也没有添加有问题的文档。
Have a look at the execution time of the function. 看一下函数的执行时间。 It should be quite small.
它应该很小。 The lambda code is not waiting for the Firestore function to be executed.
Lambda代码不等待Firestore函数执行。
As @doug-stevenson pointed out you are not using the promise. 正如@ doug-stevenson指出的那样,您没有使用诺言。 Change the lambda function to async and put a await in front of the set.
将lambda函数更改为async,然后在该集合的前面等待。 I hope that helps.
希望对您有所帮助。
exports.handler = async function(event, context, callback) {
var docRef = db.collection('users').doc('alovelace');
let setAda = await docRef.set({
first: 'Ada',
last: 'Lovelace',
born: 1815
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.