我正在尝试使用谷歌的 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 用户、服务帐户、数据库,我可以使其工作并创建这些资源。
如果有人遇到此问题,我将不胜感激。
慕桂英546537
阿波罗的战车
随时随地看视频慕课网APP
相关分类