簡體   English   中英

通過 Java API 創建 Google Cloud Function:前提條件檢查失敗

[英]Creating Google Cloud Function via Java API: Precondition check failed

我正在嘗試使用Java 客戶端 API創建 Google Cloud 函數,但不斷收到代碼 400 和消息“前提條件檢查失敗”的錯誤。

我知道這是由於我的輸入參數之一的格式錯誤,但沒有說明是哪一個。

調用代碼

CloudFunction function = new CloudFunction();
function.setName("mytest1");
function.setAvailableMemoryMb(128);
function.setSourceArchiveUrl("gs://my-bucket/path/to/source.zip"); 
function.setRuntime("python37");
function.setEntryPoint("my_function_name");
function.setTimeout("450s");

String location = "projects/my-project-id/locations/us-east4";
cloudFunctions.projects().locations().functions().create(location, function).execute(); // exception thrown here

我還嘗試將函數的serviceAccountEmail設置為我正在使用的服務帳戶密鑰,並也設置了HttpsTrigger

這個 API 的JavaDoc說只需要運行時但是只用這個集合運行它也不起作用。

錯誤

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Precondition check failed.",
    "reason" : "failedPrecondition"
  } ],
  "message" : "Precondition check failed.",
  "status" : "FAILED_PRECONDITION"
}

函數名錯誤。

function.setName("mytest1");

它應該像

function.setName("projects/{project-id}/locations/{location}/functions/{your-function-name}")

函數名稱必須全局唯一並匹配模式 projects/ /locations/ /functions/*

請參閱此鏈接

暫無
暫無

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

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