Reputation: 654
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?
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"}'
Upvotes: 5
Views: 8436
Reputation: 6284
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
Upvotes: 2
Reputation: 1011
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"}'
Upvotes: 4