Home > Mobile >  gcp cloud function returns 404 when deployed from command line
gcp cloud function returns 404 when deployed from command line

Time:02-15

If I deploy the enter image description here

I suggest you check the url you're trying to access since according to this GCP doc:

If you attempt to invoke a function that does not exist, Cloud Functions responds with an HTTP/2 302 redirect which takes you to the Google account login page. This is incorrect. It should respond with an HTTP/2 404 error response code. The problem is being addressed.

The solution

Make sure you specify the name of your function correctly. You can always check using gcloud functions call which returns the correct 404 error for a missing function.

You can also refer to this complete guide to quickstart your CF creation and deployment using the Go runtime.

CodePudding user response:

Thanks all, my project where I got stuck has more code in it than just this function. I went down this path after trying to deploy a single function/file within larger project. If I simplify down to a folder with just a hello.go and go.mod indeed it works :-/ to deploy it from command line:

gcloud functions deploy hellogo --entry-point=HelloWorld --trigger-http --region=us-central1 --memory=128MB --runtime=go116 --allow-unauthenticated

// go.mod

module github.com/nickfoden/hello

go 1.16

Thank you for the fast replies and assistance. Rather than try to create a single function within existing project with larger go.sum, multiple folders, existing server/api etc. I am going to start from here having a single file with a cloud function and build on top of it and see at what point/if I get stuck again.

  • Related