Whenever I have to deploy a new python function using the gcloud
sdk I get this message
Allow unauthenticated invocations of new function [function-name]?
(y/N)?
WARNING: Function created with limited-access IAM policy. To enable unauthorized access consider
"gcloud alpha functions add-iam-policy-binding function-name --region=europe-west1 --member=allUsers --role=roles/cloudfunctions.invoker"
Is there any flag I can add to the command to make it a NO
when deploying?
This is a sample command I use to deploy one function:
gcloud functions deploy function-name --region=europe-west1 --entry-point function-entry-point --trigger-resource "projects/my-project/databases/(default)/documents/user_ids/{user_id}" --trigger-event providers/cloud.firestore/eventTypes/document.create --runtime python37 --timeout 60 --project my-project
In the Source code field, select ZIP from Cloud Storage. In the Cloud Storage location field, click Browse to select a ZIP file from Cloud Storage. Your function source files must be located at the root of the ZIP file - see Source directory structure. Click Deploy.
Principal. A principal can be a Google Account (for end users), a service account (for applications and compute workloads), a Google group, or a Google Workspace account or Cloud Identity domain that can access a resource. Each principal has its own identifier, which is typically an email address. Role.
or
gcloud functions add-iam-policy-binding FUNCTION \
--member='serviceAccount:FUNCTION_IDENTITY' \
--role='roles/cloudfunctions.invoker'
gcloud run services add-iam-policy-binding [SERVICE_NAME] \
--member="allUsers" \
--role="roles/cloudfunctions.invoker"
I just encountered this problem as well and discovered that you can supply --no-allow-unauthenticated
to pre-emptively answer "no" to this question.
gcloud functions deploy MyFunction \
--runtime=go116 --trigger-http --no-allow-unauthenticated
From https://cloud.google.com/sdk/docs/scripting-gcloud#disabling_prompts:
You can disable prompts from gcloud CLI commands by setting the
disable_prompts
property in your configuration toTrue
or by using the global--quiet
or-q
flag.
So for your example, you could run:
gcloud functions deploy function-name --quiet --region=europe-west1 --entry-point function-entry-point --trigger-resource "projects/my-project/databases/(default)/documents/user_ids/{user_id}" --trigger-event providers/cloud.firestore/eventTypes/document.create --runtime python37 --timeout 60 --project my-project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With