Context Objects

The run_lambda module provides classes for mocking AWS Lambda Context objects. See here for more information about AWS Lambda Context objects.

MockLambdaContext class

class MockLambdaContext
aws_request_id
Property:AWS request id associated with invocation
Return type:str
client_context
Property:Information about client application and device when invoked via AWS Mobile SDK. May be None.
Return type:MockClientContext
function_name
Property:Name of function
Type:str
function_version
Property:version of Lambda function that is executing
Return type:str
get_remaining_time_in_millis()

Returns remaining execution time, in milliseconds. Should be called inside of Lambda function.

Returns:Remaining execution time, in milliseconds
Return type:int
identity
Property:Cognito identity provider. May be None.
Return type:MockCognitoIdentity
invoked_function_arn
Property:ARN used to invoke function
Return type:str
log_group_name
Property:Name of CloudWatch log group where logs are written
Return type:str
log_stream_name
Property:Name of CloudWatch log stream where logs are written
Return type:str
memory_limit_in_mb
Property:Memory limit, in MB, as a string
Return type:str

MockLambdaContext.Builder class

Using the MockLambdaContext.Builder class to construct MockLambdaContext instances is strongly encouraged.

class MockLambdaContext.Builder
__init__()

Initializes each context field to a reasonable default

build()

Constructs and returns a MockLambdaContext instance represented by the called builder object.

Returns:A newly constructed context object
Return type:MockLambdaContext
set_aws_request_id(aws_request_id)
Parameters:aws_request_id (str) – AWS request id associated with invocation
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_client_context(client_context)
Parameters:client_context (MockClientContext) – Information about client application and device
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_default_remaining_time_in_millis(default_remaining_time_in_millis)

Sets a default value that will be returned from the get_remaining_time_in_millis() method of the built MockLambdaContext value if a Lambda function is called without a timeout.

Parameters:default_remaining_time_in_millis (int) – default value
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_function_name(function_name)
Parameters:function_name (str) – name of Lambda function
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_function_version(function_version)
Parameters:function_version (str) – version of executing Lambda function
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_identity(identity)
Parameters:identity (MockCognitoIdentity) – Cognito identity provider
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_invoked_function_arn(invoked_function_arn)
Parameters:invoked_function_arn (str) – ARN used to invoke function
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_log_group_name(log_group_name)
Parameters:log_group_name (str) – Name of CloudWatch log group where logs are written
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_log_stream_name(log_stream_name)
Parameters:log_stream_name (str) – Name of CloudWatch log stream where logs are written
Returns:the updated builder
Return type:MockLambdaContext.Builder
set_memory_limit_in_mb(memory_limit_in_mb)
Parameters:memory_limit_in_mb (str) – Memory limit, in megabytes, as a string
Returns:the updated builder
Return type:MockLambdaContext.Builder

MockCognitoIdentity class

class MockCognitoIdentity
__init__(identity_id=None, identity_pool_id=None)
cognito_identity_id
Property:AWS Cognito identity id. May be None
Return type:str
cognito_identity_pool_id
Property:AWS Cognito identity pool id. May be None.
Return type:str

MockClientContext class

class MockClientContext
__init__(client, custom=None, env=None)
client
Property:Information about client
Return type:MockClientContext.Client
custom
Property:Dictionary of custom values set by client application
Return type:dict
env
Property:Dictionary of environment information provided by AWS Mobile SDK
Return type:dict

MockClientContext.Client class

class MockClientContext.Client
__init__(installation_id, app_title, app_version_name, app_version_code, app_package_name)
app_package_name
Property:App package name
Return type:str
app_title
Property:App title
Return type:str
app_version_code
Property:App version code
Return type:str
app_version_name
Property:App version name
Return type:str
installation_id
Property:Installation id
Return type:str