我一直在使用云功能很长一段时间但是最近它在使用内联编辑器通过UI创建它时给了我一个错误。我得到的错误是:
Error
The request contains invalid arguments "event_trigger": "projects/my-project-id/buckets/my-bucket-id expected to match template projects/_/buckets/{bucket}"
Tracking Number: **************(some tracking number)
基本上我正在尝试创建一个在最终启动数据流作业的特定GCS存储桶中创建/上传文件时必须触发的功能。通过Cloud SDK命令行从本地上载时,该功能将被部署,但不会被触发。 我之前以相同的方式(UI /命令行)创建了几个函数。不知道为什么它现在不起作用。
我正在使用的代码是:
const google = require('googleapis');
exports.jobName = function(event, callback) {
const file = event.data;
if (file.resourceState === 'exists' && file.name) {
console.log(file.name);
console.log(event.data);
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/userinfo.email'
]);
}
const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
dataflow.projects.templates.create({
projectId: 'project-id',
resource: {
parameters: {
inputFile: `gs://${file.bucket}/${file.name}`,
filename:`${file.name}`
},
jobName: 'cloud-fn',
gcsPath: 'gs://some-bucket/Job'
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});
});
}
};
的package.json:
{
"name": "something",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"googleapis": "^18.0.0"
}
}