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 authentication 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=rawparameter is specified.
Using the invocation context
You can use the invocation context to authenticate in the API of Yandex.Cloud services and manage the process of getting the HTTP request body (the
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 (
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.parsemethod 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.parsemethod: an object containing field keys and passed values.