简体   繁体   English

gcloud 函数部署问题

[英]gcloud functions deploy issue

I try to deploy one gcloud function with the below Github link to back up the datastore.我尝试使用以下 Github 链接部署一个 gcloud function 来备份数据存储。

https://github.com/portsoc/cloud-simple-datastore-backup/blob/master/index.js https://github.com/portsoc/cloud-simple-datastore-backup/blob/master/index.js

After updating the variant BUCKET_NAME with my cloud storage bucket name, I run it under gcloud shell with the command: node index.js and it will backup the datastore successfully.使用我的云存储桶名称更新变体 BUCKET_NAME 后,我在 gcloud shell 下使用命令运行它: node index.js它将成功备份数据存储。

but when I continue to run the below command to deploy it:但是当我继续运行下面的命令来部署它时:

gcloud functions deploy main gcloud 函数部署主要
--runtime nodejs12 --trigger-http --allow-unauthenticated --runtime nodejs12 --trigger-http --allow-unauthenticated
--region=asia-southeast2 --region=亚洲-东南2

After a while, it will give me the below error:一段时间后,它会给我以下错误:

Deploying function (may take a while - up to 2 minutes)...failed.部署 function(可能需要一段时间 - 最多 2 分钟)...失败。
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code.错误:(gcloud.functions.deploy) OperationError:代码=3,消息=加载用户代码时函数失败。 This is likely due to a bug in the user code.这可能是由于用户代码中的错误。 Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs .错误消息:错误:请检查您的 function 日志以查看错误原因: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs Additional troubleshooting documentation can be found athttps://cloud.google.com/functions/docs/troubleshooting#logging .可以在https://cloud.google.com/functions/docs/troubleshooting#logging找到其他故障排除文档。 Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.请访问https://cloud.google.com/functions/docs/troubleshooting以获得深入的故障排除文档。 Click to view the error screenshot点击查看错误截图

Any suggestion on this?对此有何建议?

Cloud Functions have a specific set of signatures that must be used. Cloud Functions 有一组必须使用的特定签名。

I'm less familiar with JavaScript|Node.JS but I think the function you reference is intended to be invoked as you do node index.js (or similar) and this is incompatible with Cloud Functions.我对 JavaScript|Node.JS 不太熟悉,但我认为您引用的 function 旨在像您执行node index.js (或类似)一样被调用,这与 Cloud Functions 不兼容。

Please review Write Cloud Functions to understand that signature type that you will need.请查看Write Cloud Functions以了解您需要的签名类型。 You will probably have to tweak the authentication in the example to better meet your needs too.您可能还需要调整示例中的身份验证,以更好地满足您的需求。

Almost certainly you don't want --allow-unauthenticated either.几乎可以肯定你也不想要--allow-unauthenticated

After changing the upload code below, I can deploy it.更改下面的上传代码后,我可以部署它。

const { GoogleAuth } = require("google-auth-library");

// fill in your bucket name here:
const BUCKET_NAME = "gs://testinbbk10";


exports.myfunction = async (req,res) =>{
  try {
    const auth = new GoogleAuth({
      scopes: "https://www.googleapis.com/auth/cloud-platform",
    });
    const client = await auth.getClient();
    const projectId = await auth.getProjectId();
    console.log(`Project ID is ${projectId}`);

    const res2 = await client.request({
      method: "POST",
      url: `https://datastore.googleapis.com/v1/projects/${projectId}:export`,
      data: {
        outputUrlPrefix: BUCKET_NAME,
      },
    });
    console.error("RESPONSE:");
    console.log(res2.data);
  } catch (error) {
    console.error("ERROR");
    console.error(error);
  }
}

but when I try to access the provided link: deploy link , it will show me the error: could not handle the request.但是当我尝试访问提供的链接: 部署链接时,它会显示错误:无法处理请求。

I am confused about how to properly deploy this to the google cloud function?我对如何将其正确部署到谷歌云 function 感到困惑? Just want to deploy one simply google cloud function to backup datastore in the google cloud.只想部署一个简单的谷歌云 function 来备份谷歌云中的数据存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gcloud 函数部署忽略点文件 - gcloud functions deploy ignores dot-files gcloud 函数部署 go 运行时错误“undefined: unsafe.Slice; Error ID: 2f5e35a0” - gcloud functions deploy go runtime error "undefined: unsafe.Slice; Error ID: 2f5e35a0" 错误:(gcloud.functions.deploy)消息=构建失败:function.js 不存在 - ERROR: (gcloud.functions.deploy) message=Build failed: function.js does not exist 错误:(gcloud.beta.functions.deploy)...消息=[调用者没有权限] - ERROR: (gcloud.beta.functions.deploy) ... message=[The caller does not have permission] 处理错误:(gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code - Dealing with ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code # 在 gcloud 上部署后出现在 url 上 - # appears on url after deploy on gcloud 如何修复错误:(gcloud.functions.deploy)PERMISSION_DENIED:权限'run.services.setIamPolicy'拒绝资源' - How to fix ERROR: (gcloud.functions.deploy) PERMISSION_DENIED: Permission 'run.services.setIamPolicy' denied on resource ' gcloud beta 运行部署 --source。 抛出 412 - gcloud beta run deploy --source . throws 412 gcloud deploy 永远不会完成更新服务 - gcloud deploy never finish with Updating service Appengine gcloud 部署使用自定义服务帐户 - Appengine gcloud deploy using custom service account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM