Python function invocation context
Invocation context is an object that contains certain execution context parameters as well as the parameters for invoking the Python function itself. It is provided to the request handler as the 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, in MB.request_id: Request ID.token: Parameters for authentication with the Yandex Cloud APIs.
The context also contains the following helper methods:
get_remaining_time_in_millis(): Returns the remaining time for the current request, in ms.
You can find an invocation context example here.
Using the invocation context
The invocation context provides the function with access to environment information, enabling it to monitor memory usage, track request execution time, and authenticate with the Yandex Cloud APIs.
Authentication with the Yandex Cloud APIs
If you specified a service account for the 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.