【问题标题】:Creating Google Cloud Function via Java API: Precondition check failed通过 Java API 创建 Google Cloud Function:前提条件检查失败
【发布时间】:2019-07-05 15:38:04
【问题描述】:

我正在尝试使用 Java Client API 创建 Google Cloud Function,但不断收到错误代码 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"
}

【问题讨论】:

    标签: java google-cloud-platform google-cloud-functions


    【解决方案1】:

    函数名错误。

    function.setName("mytest1");
    

    应该是这样的

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

    函数名称必须在全局范围内唯一并且匹配模式 projects//locations//functions/*

    请参考这个link

    【讨论】:

    • 您能否扩展您的答案以说明为什么参数应该看起来像这样,以及对于 OP 的特殊情况它会是什么样子?
    猜你喜欢
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-08
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多