簡體   English   中英

gcloud 函數部署問題

[英]gcloud functions deploy issue

我嘗試使用以下 Github 鏈接部署一個 gcloud function 來備份數據存儲。

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

使用我的雲存儲桶名稱更新變體 BUCKET_NAME 后,我在 gcloud shell 下使用命令運行它: node index.js它將成功備份數據存儲。

但是當我繼續運行下面的命令來部署它時:

gcloud 函數部署主要
--runtime nodejs12 --trigger-http --allow-unauthenticated
--region=亞洲-東南2

一段時間后,它會給我以下錯誤:

部署 function(可能需要一段時間 - 最多 2 分鍾)...失敗。
錯誤:(gcloud.functions.deploy) OperationError:代碼=3,消息=加載用戶代碼時函數失敗。 這可能是由於用戶代碼中的錯誤。 錯誤消息:錯誤:請檢查您的 function 日志以查看錯誤原因: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs 可以在https://cloud.google.com/functions/docs/troubleshooting#logging找到其他故障排除文檔。 請訪問https://cloud.google.com/functions/docs/troubleshooting以獲得深入的故障排除文檔。 點擊查看錯誤截圖

對此有何建議?

Cloud Functions 有一組必須使用的特定簽名。

我對 JavaScript|Node.JS 不太熟悉,但我認為您引用的 function 旨在像您執行node index.js (或類似)一樣被調用,這與 Cloud Functions 不兼容。

請查看Write Cloud Functions以了解您需要的簽名類型。 您可能還需要調整示例中的身份驗證,以更好地滿足您的需求。

幾乎可以肯定你也不想要--allow-unauthenticated

更改下面的上傳代碼后,我可以部署它。

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);
  }
}

但是當我嘗試訪問提供的鏈接: 部署鏈接時,它會顯示錯誤:無法處理請求。

我對如何將其正確部署到谷歌雲 function 感到困惑? 只想部署一個簡單的谷歌雲 function 來備份谷歌雲中的數據存儲。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM