Making a function public
To allow any user to invoke a function without passing an authorization header, make it public.
- In the management console
, select the folder containing the function. - 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 CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command 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)
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, 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.functionInvokerrole to all unauthorized users (All userspublic group).
For more information about the
yandex_function_iam_bindingresource parameters, see the provider documentation. -
-
Check the configuration using this command:
terraform validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planThe 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
yesinto the terminal and press 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.