1

There is a Go package for interacting with the Cloud Functions API (google.golang.org/api/cloudfunctions/v1) but I can't figure out how to use it to create new functions. I'm getting 404 and 403 errors when attempting to upload to the signed URL for the Cloud Storage bucket.

Does anyone know how to use this package to deploy Cloud Functions?

1
  • 1
    Please, provide the code, the solutions you already tried. I can only copy and paste the documentation for your general question. Commented Jan 30, 2019 at 19:30

1 Answer 1

4

I have encountered a similar issue when using google.golang.org/api/cloudfunctions/v1, the first problem with 403 error I had, was due to using auth client with presigned Generate Upload URL, using bare http client helped

httpClient := http.DefaultClient
data, err := ioutil.ReadAll(reader)
if err != nil {
    return err
}
request, err := http.NewRequest("PUT", uploadURL, bytes.NewReader(data))
if err != nil {
    return err
}
request.Header.Set("content-type", "application/zip")
request.Header.Set("x-goog-content-length-range", "0,104857600")
request.Header.Set("Content-Length", fmt.Sprintf("%d", len(data)))
response, err := httpClient.Do(request)
if err != nil {
    return err
}

Another issue I saw with 404 was when I was using location as region as opposed to the fully qualified name presented in the below snippet

var location =  'projects/${projectID}/locations/${region}'  
projectService := cloudfunctions.NewProjectsLocationsFunctionsService(ctxClient.service)
createCall := projectService.Create(location, request.CloudFunction)
createCall.Context(ctxClient.Context())
return createCall.Do()
h

You can also check golang cloud functions google.golang.org/api/cloudfunctions/v1 API usage in this project:

Cloud function service

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.