[英]firestore backup function errors with "PERMISSION_DENIED: The caller does not have permission"
I'm trying to set up a scheduled firebase function that will export all collections in Firestore every 24 hours.我正在尝试设置一个预定的 firebase function,它将每 24 小时导出一次 Firestore 中的所有 collections。 I'm using this script for that:
我为此使用了这个脚本:
import {fs} from '../services/firestore';
import * as functions from 'firebase-functions';
import * as firestore from '@google-cloud/firestore';
const client = new firestore.v1.FirestoreAdminClient();
const bucket = 'gs://my-cool-backup';
export const scheduledFirestoreExport = functions
.region('europe-west1')
.pubsub
.schedule('every 24 hours')
.onRun(async (context) => {
const collections = await fs.listCollections();
const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
const databaseName =
client.databasePath(projectId, '(default)');
const responses = await client.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
collectionIds: collections.map(x => x.id)
});
const response = responses[0];
console.log(`Operation Name: ${response['name']}`);
return response;
});
../services/firestore
looks like this: ../services/firestore
看起来像这样:
import * as settings from '../settings.json';
import * as serviceAccount from '../firebase-admin.json';
import * as admin from 'firebase-admin';
export const fs = admin.initializeApp({
credential: admin.credential.cert(serviceAccount as any),
...settings.firebase
}).firestore();
When I trigger the function using the Google Cloud Platform, this is the output:当我使用谷歌云平台触发 function 时,这是 output:
Error: function execution failed. Details:
7 PERMISSION_DENIED: The caller does not have permission
The service account I'm using has the following permissions我正在使用的服务帐户具有以下权限
I have many functions running without any problems, just this one is failing.我有很多功能运行没有任何问题,只有这个失败了。 I suspect it's because of
@google-cloud/firestore
, whereas the other ones only use firebase-admin
我怀疑这是因为
@google-cloud/firestore
,而其他的只使用firebase-admin
The error message gives me very little to go with.报错信息给我的很少 go 带。 What am I missing here?
我在这里错过了什么?
This is most certainly an issue with permission on the service account you are using.这肯定是您正在使用的服务帐户的权限问题。
You can follow this link for settings Role (roles/datastore.user) [1], [2] for firestore on service account您可以点击此链接设置 Role (roles/datastore.user) [1], [2] for firestore on service account
[1] https://cloud.google.com/firestore/docs/quickstart-servers#set_up_authentication [1] https://cloud.google.com/firestore/docs/quickstart-servers#set_up_authentication
[2] https://cloud.google.com/firestore/docs/security/iam#roles [2] https://cloud.google.com/firestore/docs/security/iam#roles
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.