简体   繁体   English

使用 go 客户端部署 GCP 云功能时,我收到:“错误 400:前提条件检查失败。,失败前提条件”

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

I'm trying to deploy a Google Cloud Function using the go client package by google.我正在尝试使用谷歌的 go 客户端包部署谷歌云功能。

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

I have broken it down into the snippet I think is most relevant:我已将其分解为我认为最相关的片段:

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

However, no matter how I format it or try.但是,无论我如何格式化或尝试。 I always get the following message:我总是收到以下消息:

googleapi: Error 400: Precondition check failed., failedPrecondition 

Through the google api explorer I ran the request with their authentication and json scheme and I received the same error.通过 google api explorer,我使用他们的身份验证和 json 方案运行了请求,但收到了同样的错误。

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

Response:回复:

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

I cannot figure out what is going wrong.我无法弄清楚出了什么问题。 I have started my own project and am the administrator.我已经开始了我自己的项目并且是管理员。 When running another part of the go client with GCP for instance creating storage, IAM user, serviceaccounts, database I can make it work and create these resources.当使用 GCP 运行 go 客户端的另一部分时,例如创建存储、IAM 用户、服务帐户、数据库,我可以使其工作并创建这些资源。

If anyone has encountered this problem I would appreciate some help.如果有人遇到过这个问题,我将不胜感激。

The eventType should match pattern : providers/*/eventTypes/*.*. eventType应该匹配模式: providers/*/eventTypes/*.*. . .

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

Also SourceRepository url should be https://source.developers.google.com/projects/*/repos/*/revisions/*/paths/ and you have https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths// SourceRepository url 应该是https://source.developers.google.com/projects/*/repos/*/revisions/*/paths/并且你有https://source.developers.google.com/projects/mytestproject/repos/deploythisfunction/moveable-aliases/master/paths//

The error message says that is an issue with the way you configure FunctionSpec , I suspect EventTrigger or SourceRepository fields.错误消息说这是您配置FunctionSpec的方式的问题,我怀疑EventTriggerSourceRepository字段。

Edit编辑

The code: 400 is a bad request, client error, in this case formatting issue, and the first thing to check is each cloud function fileds code: 400是一个错误的请求,客户端错误,在这种情况下是格式问题,首先要检查的是每个云函数文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM