簡體   English   中英

使用 go 客戶端部署 GCP 雲功能時,我收到:“錯誤 400:前提條件檢查失敗。,失敗前提條件”

[英]When deploying GCP cloud function with go client I receive: "Error 400: Precondition check failed., failedPrecondition"

我正在嘗試使用谷歌的 go 客戶端包部署谷歌雲功能。

https://pkg.go.dev/google.golang.org/api/cloudfunctions/v1?tab=doc#pkg-overview

我已將其分解為我認為最相關的片段:

import (
    "context"
    log "github.com/sirupsen/logrus"
    functions "google.golang.org/api/cloudfunctions/v1"
)

func main() {
    ctx := context.Background()
    CloudFunctionService, err := functions.NewService(ctx)
    if err != nil {
        log.Printf("Error at functions.NewService(ctx): \"%v\"\n", err)
    }
    FunctionSpec := functions.CloudFunction{
            EntryPoint:        "DeployThisFunctionEntryPoint",
            EventTrigger: &functions.EventTrigger{
                EventType: "google.pubsub.topic.publish",
                Resource:  "projects/mytestproject/topics/cloud-builds",
            },
            Name:                "DeployThisFunction",
            Runtime:             "go111",
            SourceRepository:    &functions.SourceRepository{Url: "https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths//"},
    }
    CloudFunctionDeploymentService := functions.NewProjectsLocationsFunctionsService(CloudFunctionService)
    createCall := CloudFunctionDeploymentService.Create("projects/mytestproject/locations/us-central1", &FunctionSpec)
    resp, err := createCall.Context(ctx).Do()
    if err != nil {
        log.Printf("Error at createCall.Context(ctx).Do(): \"%v\"\n", err)
    }
    log.Printf("response createCall.Context(ctx).Do(): \"%v\"\n", resp)
}

但是,無論我如何格式化或嘗試。 我總是收到以下消息:

googleapi: Error 400: Precondition check failed., failedPrecondition 

通過 google api explorer,我使用他們的身份驗證和 json 方案運行了請求,但收到了同樣的錯誤。

https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/create

回復:

{
  "error": {
    "code": 400,
    "message": "Precondition check failed.",
    "status": "FAILED_PRECONDITION"
  }
}

我無法弄清楚出了什么問題。 我已經開始了我自己的項目並且是管理員。 當使用 GCP 運行 go 客戶端的另一部分時,例如創建存儲、IAM 用戶、服務帳戶、數據庫,我可以使其工作並創建這些資源。

如果有人遇到過這個問題,我將不勝感激。

eventType應該匹配模式: providers/*/eventTypes/*.*. .

例如: providers/cloud.pubsub/eventTypes/topic.publish

SourceRepository url 應該是https://source.developers.google.com/projects/*/repos/*/revisions/*/paths/並且你有https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths//

錯誤消息說這是您配置FunctionSpec的方式的問題,我懷疑EventTriggerSourceRepository字段。

編輯

code: 400是一個錯誤的請求,客戶端錯誤,在這種情況下是格式問題,首先要檢查的是每個雲函數文件

暫無
暫無

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

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