Making a function public
To allow any user to invoke a function without passing an authorization header, make it public.
- In the management console
, go to the folder the function is in. - Select Cloud Functions.
- Select the function you want to make public.
- On the Overview page, enable Public function.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To make a function public, run the command:
yc serverless function allow-unauthenticated-invoke <function_name>
Result:
done (1s)
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To make a function public:
-
Describe the properties of the function access rights in a configuration file:
resource "yandex_function_iam_binding" "function-iam" { function_id = "<function_ID>" role = "functions.functionInvoker" members = [ "system:allUsers", ] }
Where:
-
function_id
: Function ID. To find out the function ID, get a list of functions in the folder. -
role
: Role to assign. -
members
: List of users to assign the role to.To make a function public, assign the
functions.functionInvoker
role to all unauthorized users (All users
public group).
For more information about the
yandex_function_iam_binding
resource parameters, see the provider documentation . -
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and click Enter.You can check the assignment of the function role using the management console
or this CLI command:yc serverless function list-access-bindings <function_name>
To make a function public, use the setAccessBindings REST API method for the Function resource or the FunctionService/SetAccessBindings gRPC API call.