Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
Yandex Cloud Functions
  • Comparison with other Yandex Cloud services
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Using functions to get an IAM token for a service account
    • Connecting to managed databases from functions
    • Getting information about a function
    • Managing rights to access functions
      • Making a function public
      • Making a function private
      • Viewing roles assigned to a function
      • Assigning roles to a function
      • Revoking roles assigned to a function
    • Creating a function
    • Invoking a function
    • Managing functions
    • Getting information about a trigger
    • Creating a trigger
    • Managing triggers
  • Concepts
  • Developing in Node.js
  • Developing in Python
  • Developing in Go
  • Developing in PHP
  • Developing in Bash
  • Developing in Java
  • Developing in R
  • Developing in C#
  • Practical guidelines
  • Pricing policy
  • Access management
  • API Functions reference
  • API Triggers reference
  • Questions and answers
  1. Step-by-step instructions
  2. Managing rights to access functions
  3. Making a function public

Making a function public

Written by
Yandex Cloud

    To allow any user to invoke a function without passing an authorization header, make it public.

    Management console
    CLI
    Terraform
    API
    1. In the management console, select the folder containing your function.
    2. Select Cloud Functions.
    3. Select the function you want to make public.
    4. 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:

    1. 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.

    2. Check the configuration using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. 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.

    4. Apply the configuration changes:

      terraform apply
      
    5. 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.

    Was the article helpful?

    Language / Region
    Yandex project
    © 2023 Yandex.Cloud LLC