Python function invocation context
Invocation context is an object that contains certain execution context parameters as well as invocation parameters for the Python function itself. It is accepted by the call handler as its second argument.
The invocation context contains:
function_folder_id: Folder containing the function.function_name: Function ID.function_version: Function version ID.deadline_ms: Unix timestamp of when the function times out, in ms. Theget_remaining_time_in_millis()function returns the interval between this timestamp and the current time.memory_limit_in_mb: Amount of memory specified when creating the version, MB.request_id: Request ID.token: Parameters for authentication in the APIs of Yandex Cloud services.
The context also contains the following helper methods:
get_remaining_time_in_millis(): Returns the remaining time for the current request, in ms.
Using the invocation context
Invocation context is required for a function to have access to environment information so that it can monitor memory usage, track request execution time, and authenticate in the Yandex Cloud service API.
Authentication in the Yandex Cloud API
If you specified a service account for a function, the token parameter contains authentication information for that service account:
access_token: IAM token.expires_in: Token’s remaining lifetime calculated when calling the function, in seconds.token_type: Token type, e.g.,Bearer.
You can also get this information using the metadata service. For more information about this method, see Authentication from within a VM.