AWS Lambda Context class for type checking and testing
Project description
A micro library that provides the AWS Lambda Context class for type checking and testing.
Installing
pip install aws-lambda-context
Usage
Import the LambdaContext on your handler file and type hint the lambda function with it:
from aws_lambda_context import LambdaContext
def my_lambda_handler(event: Any, context: LambdaContext) -> None:
...
The type hint should enables type checking with mypy and editor auto-completion
The class is also useful as a mock during tests:
from aws_lambda_context import (
LambdaClientContext,
LambdaClientContextMobileClient,
LambdaCognitoIdentity,
LambdaContext
)
def test_handler():
lambda_cognito_identity = LambdaCognitoIdentity()
lambda_cognito_identity.cognito_identity_id = 'cognito_identity_id'
lambda_cognito_identity.cognito_identity_pool_id = 'cognito_identity_pool_id'
lambda_client_context_mobile_client = LambdaClientContextMobileClient()
lambda_client_context_mobile_client.installation_id = 'installation_id'
lambda_client_context_mobile_client.app_title = 'app_title'
lambda_client_context_mobile_client.app_version_name = 'app_version_name'
lambda_client_context_mobile_client.app_version_code = 'app_version_code'
lambda_client_context_mobile_client.app_package_name = 'app_package_name'
lambda_client_context = LambdaClientContext()
lambda_client_context.client = lambda_client_context_mobile_client
lambda_client_context.custom = {'custom': True}
lambda_client_context.env = {'env': 'test'}
lambda_context = LambdaContext()
lambda_context.function_name = 'function_name'
lambda_context.function_version = 'function_version'
lambda_context.invoked_function_arn = 'invoked_function_arn'
lambda_context.memory_limit_in_mb = 'memory_limit_in_mb'
lambda_context.aws_request_id = 'aws_request_id'
lambda_context.log_group_name = 'log_group_name'
lambda_context.log_stream_name = 'log_stream_name'
lambda_context.identity = lambda_cognito_identity
lambda_context.client_context = lambda_client_context
assert handler({}, lambda_context) == 'something'
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for aws_lambda_context-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f93fb94fd292e7c75fd5d55ce4e7895ee7a6d71f6ddcccd694e54f13144a7cc |
|
MD5 | 7a3089e1e47a4102acb45225547583e5 |
|
BLAKE2b-256 | 8d451a6eab1cd292d47bcb8bd3af514168e0a62e502442ef554774d44d1cfe0b |