Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Cloud Functions
  • Getting started
    • Overview
    • Creating and executing functions
    • Creating a timer
    • Creating a trigger for Message Queue
    • Creating a trigger for Object Storage
    • Creating a trigger for Container Registry
    • Creating a trigger for Cloud Logs
    • Creating a trigger for IoT Core
  • Step-by-step instructions
    • All instructions
    • Using functions to get an IAM token for a service account
    • Managing rights to access functions
    • Managing functions
      • Creating a function
      • Managing function versions
      • Working in the code editor
      • Invoking a function
      • Updating a function
      • Viewing monitoring charts
      • Viewing the execution log
      • Deleting a function
    • Managing triggers
      • Getting information about a trigger
      • Creating a timer
      • Creating a trigger for Message Queue
      • Creating a trigger for Object Storage
      • Creating a trigger for Container Registry
      • Creating a trigger for Cloud Logs
      • Creating a trigger for Yandex IoT Core
      • Updating a trigger
      • Deleting a trigger
  • Concepts
    • Overview
    • Function
    • Invoking a function
    • Runtime
      • Overview
      • Environment
      • Execution context
    • Builder
    • Trigger
      • Overview
      • Timer
      • Trigger for Message Queue
      • Trigger for Object Storage
      • Trigger for Container Registry
      • Trigger for Cloud Logs
      • Trigger for Yandex IoT Core
    • Dead Letter Queue
    • Log groups
    • Monitoring
    • Backups
    • Quotas and limits
  • Developing in Node.js
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in Python
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in Go
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in PHP
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
  • Developing in Bash
    • Overview
    • Request handler
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in Java
    • Overview
    • Programming model
      • Overview
      • Function interface
      • YcFunction interface
      • HttpServlet class
      • Spring Boot
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in R
    • Overview
    • Programming model
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
  • Developing in C#
    • Overview
    • Programming model
      • Overview
      • Function interface
      • YcFunction interface
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Use cases
    • Creating skills for Alice
  • Pricing policy
  • Access management
  • API Functions reference
    • Authentication in the API
    • gRPC
      • Overview
      • FunctionService
      • OperationService
    • REST
      • Overview
      • Function
        • Overview
        • create
        • createVersion
        • delete
        • get
        • getVersion
        • getVersionByTag
        • list
        • listAccessBindings
        • listOperations
        • listRuntimes
        • listTagHistory
        • listVersions
        • removeTag
        • setAccessBindings
        • setTag
        • update
        • updateAccessBindings
  • API Triggers reference
    • Authentication in the API
    • gRPC
      • Overview
      • TriggerService
      • OperationService
    • REST
      • Overview
      • Trigger
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • pause
        • resume
        • update
  • Questions and answers
  1. Step-by-step instructions
  2. Managing functions
  3. Invoking a function

Invoking a function

  • Invoking a function
  • Authentication when invoking a private function via HTTP

Note

To allow any user to invoke (call) a function, make it public. For more information about rights, see Access management.

To access a function, use its name or unique ID. To find them, get a list of functions in a folder.

Invoking a function

As an example, we'll use the function described in Creating a function version.

Management console
HTTP
CLI

Invoke the function:

  1. Select Cloud Functions in management console.
  2. Click in the row of the function you want to invoke.
  3. In the window that opens, go to Testing.
  4. In the Tag version field, specify which function version to invoke.
  5. Under Payload template, choose one of the options:
    • Without preset: Custom data format.
    • HTTP call: HTTP call data format for a function acting as an HTTP request handler.
    • Trigger for Message Queue: Data format for the function called by a trigger in order to process messages from the queue.
  6. In the Input field, enter the input data to test the function.
  7. Click Run test.
  8. You will see the testing status under Test result in the Function status field. Important: The maximum function execution time before timeout (including original initialization at first call) is 10 minutes.
  9. You will see the data processed by the function in the Function output field.

Note

For security reasons, the function can only be called using TLS protocol.

Call the function as a regular HTTP request, such as by entering the function call link in your browser address bar. Call link format:

https://functions.yandexcloud.net/<function ID>

The function call link is also shown in the http_invoke_url parameter when creating a function.

You can call a specific function version using the tag parameter. The function with the $latest tag is called by default.

  • Example of function call with no additional parameters:

    https://functions.yandexcloud.net/b09bhaokchn9pnbrlseb
    

    The response depends on the function you call. In this case, it will be as follows:

    Hello, World!
    
  • Example of function call with the name parameter added to the URL:

    https://functions.yandexcloud.net/b09bhaokchn9pnbrlseb?name=<user name>
    

    The following response appears on the page:

    Hello, Username!
    
  • Example of calling a specific function version with the tag parameter added to the URL:

    https://functions.yandexcloud.net/b09bhaokchn9pnbrlseb?tag=<version tag>
    

You can call a specific function version using the --tag parameter. The function with the $latest tag is called by default.

  • Call the function by specifying in the parameter a name for еру greeting:

    $ yc serverless function invoke <function ID> -d '{"queryStringParameters": {"name": "Username"}}'
    

    Result:

    {"statusCode": 200, "headers": {"Content-Type": "text/plain"}, "isBase64Encoded": false, "body": "Hello, Username!"}
    
  • Use a tag to call a specific function version:

    $ yc serverless function invoke <function ID> --tag <function version tag>
    

To learn more about function structure dependence for different invocation methods (HTTP and CLI), see Invoking a function.

Authentication when invoking a private function via HTTP

To invoke a private function via HTTP, you must authenticate. To do this, get:

  • IAM token:

    • Instructions for a Yandex account.
    • Instructions for a service account.
    • Instructions for a federated account.

    Pass the obtained IAM token in the Authorization header using the following format:

    Authorization: Bearer <IAM-TOKEN>
    

    IAM tokens are valid for 12 hours maximum.

  • API key for the service account.

    Pass the obtained API key in the Authorization header using the following format:

    Authorization: Api-Key <API key>
    

    API keys do not expire. This means that this authentication method is simpler, but less secure. Use it if you can't request an IAM token automatically.

In this article:
  • Invoking a function
  • Authentication when invoking a private function via HTTP
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC