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 your function.
- Select Cloud Functions.
- Select the function you want to make public.
- On the Overview page, under General information, switch the Public function option to on.
If you don't 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)
With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.
For more information about the provider resources, see the documentation on the Terraform site or mirror site.
If you change the configuration files, Terraform automatically determines 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 = "serverless.functions.invoker" 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
serverless.functions.invoker
role to all unauthorized users (allUsers
system group).
For more information about the parameters of the
yandex_function_iam_binding
resource, see the provider documentation. -
-
Check the configuration using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can check that the function role has been assigned using the management console or the CLI command:
yc serverless function list-access-bindings <function_name>
You can make a function public using the setAccessBindings API method.