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. Developing in Node.js
  2. Invocation context

Invocation context

  • Using the invocation context
    • Authentication in the Yandex.Cloud API
    • Getting the request body

Invocation context is an object that is accepted by the request handler as the second argument.

The invocation context provides additional information about function version properties:

  • functionName: The function ID.
  • functionVersion: The function version ID.
  • memoryLimitInMB: The amount of memory specified when creating the version, MB.
  • requestId: The ID of the request being handled.
  • token: The parameters required for authentification in the Yandex.Cloud API.

The context also contains the following helper methods:

  • getRemainingTimeInMillis(): Returns the time, in ms, remaining to complete the current request.
  • getPayload(): Returns the request body if HTTP integration is used. By default, HTTP integration is used for all functions invoked if no integration=raw parameter is specified.

Using the invocation context

You can use the invocation context to authenticate in the Yandex.Cloud API and manage the process of getting the HTTP request body (the body parameter).

Authentication in the Yandex.Cloud API

If a function has a specified service account, the token parameter contains information for authentication on behalf of this service account:

  • access_token: The IAM token.
  • expires_in: The token lifetime in seconds.
  • token_type: The token type (Bearer).

You can also get this information using the metadata service. For more information, see Authenticating from inside a VM.

Getting the request body

getPayload() is a helper method that makes it easier to get the request body (the body parameter). Depending on the content of the request body and header, the function handles data using different methods:

  • If a JSON document is passed as the request body and the header is set to Content-Type: application/json, the function returns the result of executing the JSON.parse method over the data that is passed in the request body.
  • If form parameters are passed as the request body and the header is set to Content-Type: application/x-www-form-urlencoded, the function returns the result of executing the querystring.parse method: an object containing field keys and passed values.
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC