在 Shell 工作區中管理函式

本頁面說明如何在單一工作區中管理多個 Cloud Functions 設定,以及如何使用 Cloud Code 重新排列 Cloud Run 函式探索器。

事前準備

本指南需要您先設定工作區 (launch.json 檔案,其中至少列出一個設定)。如要開始使用範例,請參閱「建立及部署函式」快速入門導覽課程。

在單一工作區中管理多個設定

如要將新的 Cloud Function 設定新增至 launch.json 檔案,請按照下列步驟操作:

  1. 按一下「Cloud Code」,然後展開「Cloud Functions」探索工具。

  2. 在 Cloud Run 函式探索器中,按一下「工作區」右鍵,然後點選「新增 Cloud Function 設定」

  3. 按照提示操作,並執行下列動作:

    1. 輸入函式名稱
    2. 選取 Cloud Run 函式環境
    3. 輸入進入點 (要呼叫此函式的名稱)
    4. 輸入測試輸入內容

    或者,您也可以手動在 launch.json 檔案中輸入這些值:

    {
        "configurations": [
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-get",
            "gen": "GEN_2",
            "entryPoint": "helloGet"
          }
        ]
    }
    

    Cloud Run 函式工作區會對應至 launch.json 檔案中列出的首個設定。工作區名稱會反映 launch.json 檔案中列出的第一個設定的 functionName

    {
        "configurations": [
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-pub-sub",
            "gen": "GEN_2",
            "entryPoint": "helloPubSub"
          },
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-get",
            "gen": "GEN_2",
            "entryPoint": "helloGet"
          }
        ]
    }
    
  4. (選用) 如要從 launch.json 檔案部署其他設定,請將要部署的設定移至 launch.json 檔案頂端,然後按一下「更新」「Cloud Functions Explorer」。

將 Cloud Run 函式 Explorer 重新排列至 IDE 的檔案 Explorer

您可以執行下列操作,將 Cloud Run 函式 Explorer 重新排列至 Cloud Shell 的檔案總管:

  1. 將 Cloud Run 函式 Explorer 拖曳至 Cloud Shell 的檔案總管:

    重新排列 Cloud Functions Explorer

    這種安排會在檔案總管下方顯示 Cloud Run 函式總管,讓您能夠在與專案檔案相同的窗格中,查看已部署的函式和 Cloud Run 函式工作區。

  2. (選用) 如要復原這項安排,請將「Cloud Code: Cloud Functions」Explorer 的標題拖回「Cloud Code」Explorer。