Making a function public
To allow any user to invoke a function without providing an authorization header, make it public.
- In the management console
, navigate to the folder containing the function. - Go to 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 yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To make a function public, run this 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 function access permissions in the 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 the 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 (theAll userspublic group).
For more information about the
yandex_function_iam_bindingproperties, see this provider guide. -
-
Validate your configuration using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.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.