Module aws_lambda_powertools.utilities.typing

Typing for developer ease in the IDE

Sub-modules

aws_lambda_powertools.utilities.typing.lambda_client_context
aws_lambda_powertools.utilities.typing.lambda_client_context_mobile_client
aws_lambda_powertools.utilities.typing.lambda_cognito_identity
aws_lambda_powertools.utilities.typing.lambda_context

Classes

class LambdaContext

The LambdaContext static object can be used to ease the development by providing the IDE type hints.

Example

A Lambda function using LambdaContext

>>> from typing import Any
>>> from aws_lambda_powertools.utilities.typing import LambdaContext
>>>
>>> def handler(event: dict[str, Any], context: LambdaContext) -> dict[str, Any]:
>>>     # Insert business logic
>>>     return event
Expand source code
class LambdaContext:
    """The LambdaContext static object can be used to ease the development by providing the IDE type hints.

    Example
    -------
    **A Lambda function using LambdaContext**

        >>> from typing import Any
        >>> from aws_lambda_powertools.utilities.typing import LambdaContext
        >>>
        >>> def handler(event: dict[str, Any], context: LambdaContext) -> dict[str, Any]:
        >>>     # Insert business logic
        >>>     return event

    """

    _function_name: str
    _function_version: str
    _invoked_function_arn: str
    _memory_limit_in_mb: int
    _aws_request_id: str
    _log_group_name: str
    _log_stream_name: str
    _identity: LambdaCognitoIdentity
    _client_context: LambdaClientContext

    @property
    def function_name(self) -> str:
        """The name of the Lambda function."""
        return self._function_name

    @property
    def function_version(self) -> str:
        """The version of the function."""
        return self._function_version

    @property
    def invoked_function_arn(self) -> str:
        """The Amazon Resource Name (ARN) that's used to invoke the function. Indicates if the invoker specified a
        version number or alias."""
        return self._invoked_function_arn

    @property
    def memory_limit_in_mb(self) -> int:
        """The amount of memory that's allocated for the function."""
        return self._memory_limit_in_mb

    @property
    def aws_request_id(self) -> str:
        """The identifier of the invocation request."""
        return self._aws_request_id

    @property
    def log_group_name(self) -> str:
        """The log group for the function."""
        return self._log_group_name

    @property
    def log_stream_name(self) -> str:
        """The log stream for the function instance."""
        return self._log_stream_name

    @property
    def identity(self) -> LambdaCognitoIdentity:
        """(mobile apps) Information about the Amazon Cognito identity that authorized the request."""
        return self._identity

    @property
    def client_context(self) -> LambdaClientContext:
        """(mobile apps) Client context that's provided to Lambda by the client application."""
        return self._client_context

    @staticmethod
    def get_remaining_time_in_millis() -> int:
        """Returns the number of milliseconds left before the execution times out."""
        return 0

Static methods

def get_remaining_time_in_millis() ‑> int

Returns the number of milliseconds left before the execution times out.

Instance variables

prop aws_request_id : str

The identifier of the invocation request.

Expand source code
@property
def aws_request_id(self) -> str:
    """The identifier of the invocation request."""
    return self._aws_request_id
prop client_context : LambdaClientContext

(mobile apps) Client context that's provided to Lambda by the client application.

Expand source code
@property
def client_context(self) -> LambdaClientContext:
    """(mobile apps) Client context that's provided to Lambda by the client application."""
    return self._client_context
prop function_name : str

The name of the Lambda function.

Expand source code
@property
def function_name(self) -> str:
    """The name of the Lambda function."""
    return self._function_name
prop function_version : str

The version of the function.

Expand source code
@property
def function_version(self) -> str:
    """The version of the function."""
    return self._function_version
prop identity : LambdaCognitoIdentity

(mobile apps) Information about the Amazon Cognito identity that authorized the request.

Expand source code
@property
def identity(self) -> LambdaCognitoIdentity:
    """(mobile apps) Information about the Amazon Cognito identity that authorized the request."""
    return self._identity
prop invoked_function_arn : str

The Amazon Resource Name (ARN) that's used to invoke the function. Indicates if the invoker specified a version number or alias.

Expand source code
@property
def invoked_function_arn(self) -> str:
    """The Amazon Resource Name (ARN) that's used to invoke the function. Indicates if the invoker specified a
    version number or alias."""
    return self._invoked_function_arn
prop log_group_name : str

The log group for the function.

Expand source code
@property
def log_group_name(self) -> str:
    """The log group for the function."""
    return self._log_group_name
prop log_stream_name : str

The log stream for the function instance.

Expand source code
@property
def log_stream_name(self) -> str:
    """The log stream for the function instance."""
    return self._log_stream_name
prop memory_limit_in_mb : int

The amount of memory that's allocated for the function.

Expand source code
@property
def memory_limit_in_mb(self) -> int:
    """The amount of memory that's allocated for the function."""
    return self._memory_limit_in_mb