Error: Page not found The requested URL was not found on this server. google cloud functions
Asked Answered
D

2

5

I'm using google cloud's "Hello World" demo for cloud functions but the URL it produces gives me an error:

Error: Page not found
The requested URL was not found on this server.

I follow the tutorial, check allow unauthenticated, etc yet the url trigger leads me to the error.

The curl response requested also returns an error:

curl -X POST MY_URL  -H "Content-Type:application/json"  -d '{"name":"Jane"}'

returns:

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Page not found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Page not found</h1>
<h2>The requested URL was not found on this server.</h2>
<h2></h2>
</body></html>

Any ideas why?

edit: testing works just fine enter image description here

Edit2: the url in MY_URL is structured like this: curl -X POST https://us-west1-PROJECT-NAME.cloudfunctions.net/FUNCTION-NAME -H "Content-Type:application/json" -d '{"message":"Jane"}'

Daphie answered 9/2, 2022 at 22:7 Comment(3)
It's very probable that you're incorrectly referencing the Function's URL when you curl the endpoint. If you click the "TRIGGER" tab, it will present you with the URL. Or you can use gcloud functions describe ${FUNCTION} --project=${PROJECT} --format="value(httpsTrigger.url)"Mayne
Your console output shows you applying {"message": "test"} to the service but your curl using {"name":"jane"}. You want to use {"message": "test"} (since you know this works). But that's another issue.Mayne
When I run that command I get the same URL that I've had already EDIT: That url also matches the trigger tabDaphie
D
4

According to this GCP doc:

As of January 15, 2020, all HTTP functions by default require most invokers to be authenticated. To allow unauthenticated invocation you must specify this at or after deployment.

After deployment, manually add the Cloud Functions Invoker permission to allUsers users in the Cloud Functions page in the Google Cloud Console.

However, it's always a best practice to set authorization on your cloud functions.

I was able to curl the endpoint successfully using:

curl -X POST https://us-central1-<project_name>.cloudfunctions.net/<function_name> -H "Authorization:
     bearer $(gcloud auth print-identity-token)" -H "Content-Type:application/json" -d '{"name": "Jane"}'

Output: enter image description here

Dramatics answered 10/2, 2022 at 12:4 Comment(4)
I currently have my Cloud Functions Invoker set to allUsers and I also tried with my specific admin authentication. Still get the same error unfortunately.Daphie
Have you tried to recreate the function? Delete and deploy the function again. @DaphieDramatics
I have, but that did not work. It turns out that it didn't like me using the us-west1 region. When I built again in the us-central1 it worked. I'm betting there's a flag that will allow me to look within a certain region for the function, do you happen to know what that is?Daphie
Also, this seemed to work fine gcloud functions call FUNCTION_NAME --data '{"name":"Keyboard Cat"}'Daphie
I
2

This error can also happen if you create a Cloud Function with a custom Service Account that doesn't have appropriate permissions.

Make sure the Service Account includes these roles:

Cloud Functions Developer
Cloud Functions Service Agent

I'm assuming that the Service Account fails to create the URL resource.

More info:

https://cloud.google.com/functions/docs/concepts/iam https://cloud.google.com/functions/docs/reference/iam/roles

Intercommunion answered 17/7, 2023 at 23:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.