当前位置: 首页 > 知识库问答 >
问题:

谷歌云功能部署失败

郎健柏
2023-03-14

当我运行gcloud函数deploy gcp_test——trigger resource xxx-test-123——trigger event google时。存储对象我发现语法错误。

错误:(gcloud.functions.deploy)操作错误:code=3,message=Function load错误:文件索引中的代码。无法加载js。你的代码中有语法错误吗?详细堆栈跟踪:/user\u代码/索引。js:1(函数(导出、要求、模块、_文件名、_目录名){#index.js^

SyntaxError:对象的createScript(vm.js:56:10)上的令牌无效或意外。在模块上运行InthisContext(vm.js:97:10)_在对象处编译(module.js:549:28)。模块_扩展。。js(module.js:586:10)在模块中。在函数tryModuleLoad(module.js:453:12)处加载(module.js:494:32)。模块_在模块处加载(module.js:445:3)。require(module.js:504:17)at require(internal/module.js:20:19)at getUserFunction(/var/tmp/worker/worker.js:388:24)

我不知道为什么会出现这个错误。我已经安装了npm模块@google云/存储。任何帮助都很感激。这个函数被认为是启用堆栈驱动程序日志记录。参考:https://medium.com/google-cloud/encrypting-stackdriver-logging-sinks-using-customer-managed-encryption-keys-for-gcs-ccd0b59f0a3

    # index.js
            'use strict';
            const Buffer = require('safe-buffer').Buffer;
            // Imports the Google Cloud client library
            const Storage = require('@google-cloud/storage');
            // Creates a client
            const storage = new Storage();
            exports.moveFileToEncryptedStorage = (event, callback) => {
              const file = event.data;
              console.log(  Event ${event.eventId});
              console.log(  Event Type: ${event.eventType});
              console.log(  Bucket: ${file.bucket});
              console.log(  File: ${file.name});
              console.log(  Metageneration: ${file.metageneration});
              console.log(  Created: ${file.timeCreated});
              console.log(  Updated: ${file.updated});
            const newBucket = "xxx-test-123";
            const newBucketAndFileName = "gs://"+newBucket+"/"+file.name;
            console.log("Moving to..."+newBucketAndFileName);
            return storage
                  .bucket(file.bucket)
                  .file(file.name)
                  .move(newBucketAndFileName)
                  .then(() => {
            
                    console.log("content has been moved to "+newBucketAndFileName);
            })
                  .catch((err) => {
                    console.error("ERROR:"+err);
                  });
            }

共有1个答案

越源
2023-03-14

删除以下行#index.js就可以了。请记住,所有console.log行应该如下所示:console.log("事件${event.eventId}");

 类似资料:
  • 从今天开始,我无法使用gCloud cli部署云功能。 下面是我部署云功能的gloud命令: 我有个错误: 部署功能(可能需要一段时间-最多2分钟)...失败。 错误:(gcloud.functions.deploy)操作错误:代码=3,消息=生成失败:生成已超时 我曾经在一个小时前编写过相同的脚本,但现在,团队中没有人能够部署云功能,并得到相同的错误。 在stackDrive日志中,我只看到以下

  • 我尝试使用my console在谷歌云平台上部署云功能。我使用的命令是, 但我得到了这个错误, 错误:(gcloud.functions.deploy)操作错误:代码=3,消息=Build failed:无法解析存储源:googleapi:错误404:未找到,未找到 我试着在谷歌上搜索,但似乎以前没有人遇到过这个错误消息。我也尝试过改变项目,部署效果很好。 如果有人知道是什么导致了这个错误,以及我

  • 我创建了一个服务帐户,并为其分配了访问云功能的权限: gcloud beta函数add-iam-policy-binding MyFunction--member=serviceaccount:cf-access@my-project.iam.gserviceaccount.com--role=roles/cloudfunctions.admin 产出: 现在,我下载了服务帐户json文件。 所以

  • 我正在使用cloud函数部署python函数(版本=3.7,内存=1go,超时=1s)。 到目前为止,它非常有效。 但是,我注意到,默认情况下,云函数将其区域设置为。我需要我的函数在中,所以我使用

  • 每当我必须使用sdk部署一个新的python函数时,我都会收到这条消息 是否允许未经验证的调用新函数[函数名]? (y/N)? 警告:使用限制访问IAM策略创建的函数。要启用未经授权的访问,请考虑 “gcloud alpha函数添加iam策略绑定函数名--region=europe-west1--member=allUsers--role=roles/cloudfunctions.invoker”

  • 刚刚完成Hello World谷歌云功能教程,收到以下响应头: