def __init__(self, scope: Stack): super().__init__( scope=scope, id=f'{TestingStack.global_prefix()}TestingFunction1', code=Code.from_inline( 'from b_lambda_layer_common import api_gateway\n' 'from b_lambda_layer_common import exceptions\n' 'from b_lambda_layer_common import ssm\n' 'from b_lambda_layer_common import util\n' 'import boto3\n' 'import botocore\n' '\n\n' 'def handler(*args, **kwargs):\n' ' return dict(\n' ' Boto3Version=boto3.__version__,\n' ' BotocoreVersion=botocore.__version__,\n' ' )' '\n'), handler='index.handler', # Ensure Python 3.8 matches everywhere. runtime=Runtime.PYTHON_3_8, layers=[ Layer(scope=scope, name=f'{TestingStack.global_prefix()}TestingLayer1', dependencies={ 'boto3': PackageVersion.from_string_version('1.16.35'), 'botocore': PackageVersion.from_string_version('1.19.35'), }) ])
def __init__(self, scope: Stack): super().__init__( scope=scope, id=f'{TestingStack.global_prefix()}FunctionWithUnitTests', code=Code.from_asset(root), handler='handler.handler', runtime=Runtime.PYTHON_3_8, timeout=Duration.minutes(5), memory_size=512, layers=[ Layer( scope=scope, name= f'{TestingStack.global_prefix()}TestingLayerWithUnitTests', dependencies={ # These dependencies are required for running unit tests inside lambda functions. # Pytest is used for running actual unit tests. 'pytest': PackageVersion.from_string_version('6.2.5'), # Pook is used for HTTP mocking, therefore it is also needed here. 'pook': PackageVersion.from_string_version('1.0.1'), # Not sure about this dependency. Lambda runtime throws errors if its missing. 'aws-cdk.core': PackageVersion.from_string_version('1.99.0'), # This dependency should be installed with 'pook' since it depends on 'jsonschema' which depends on this. # For some reason it doesn't. # Tests would fail with import error otherwise. 'importlib-resources': PackageVersion.from_string_version('5.4.0') }) ])
def __init__(self, scope: Stack): super().__init__( scope=scope, id=f'{TestingStack.global_prefix()}TestingFunction3', code=Code.from_inline( 'import urllib3\n' 'from jose import jwk, jwt\n' 'from jose.utils import base64url_decode\n' 'from b_lambda_layer_common import api_gateway\n' 'from b_lambda_layer_common import exceptions\n' 'from b_lambda_layer_common import util\n' 'from b_lambda_layer_common.ssm.ssm_parameter import SSMParameter\n' 'import boto3\n' 'import botocore\n' '\n\n' 'def handler(*args, **kwargs):\n' ' SSMParameter("TestSSMParam")\n\n' ' return dict(\n' ' Boto3Version=boto3.__version__,\n' ' BotocoreVersion=botocore.__version__,\n' ' )' '\n'), handler='index.handler', # Ensure Python 3.8 matches everywhere. runtime=Runtime.PYTHON_3_8, layers=[ Layer(scope=scope, name=f'{TestingStack.global_prefix()}TestingLayer3', dependencies={ 'python-jose': PackageVersion.from_string_version('3.3.0') }) ])
def __init__(self, scope: Construct): super().__init__(scope=scope) function = Function( scope=self, id=f'{self.global_prefix()}TestingFunction', code=Code.from_inline( 'from b_lambda_layer_common import api_gateway\n' 'from b_lambda_layer_common import exceptions\n' 'from b_lambda_layer_common import ssm\n' 'from b_lambda_layer_common import util\n' 'import boto3\n' 'import botocore\n' '\n\n' 'def handler(*args, **kwargs):\n' ' return dict(\n' ' Boto3Version=boto3.__version__,\n' ' BotocoreVersion=botocore.__version__,\n' ' )' '\n'), handler='index.handler', runtime=Runtime.PYTHON_3_6, layers=[ Layer(scope=self, name=f'{self.global_prefix()}TestingLayer', dependencies={ 'boto3': PackageVersion.from_string_version('1.16.35'), 'botocore': PackageVersion.from_string_version('1.19.35'), }) ]) self.add_output(self.LAMBDA_FUNCTION_NAME_KEY, value=function.function_name) # Create another function that is not using boto3. Function( scope=self, id=f'{self.global_prefix()}TestingFunction2', code=Code.from_inline('def handler(*args, **kwargs): return 200'), handler='index.handler', runtime=Runtime.PYTHON_3_6, layers=[ Layer(scope=self, name=f'{self.global_prefix()}TestingLayer2') ])
def __init__( self, scope: Stack, name: str, additional_pip_install_args: Optional[str] = None, dependencies: Optional[Dict[str, PackageVersion]] = None, docker_image: Optional[str] = None, ) -> None: super().__init__( scope, name, source_path=self.get_source_path(), code_runtimes=self.runtimes(), additional_pip_install_args=additional_pip_install_args, dependencies={ **(dependencies or {}), 'pynamodb': PackageVersion.from_string_version('5.2.1'), 'ordered-set': PackageVersion.from_string_version('4.1.0'), 'cryptography': PackageVersion.from_string_version('37.0.1') }, # Ensure Python 3.8 matches everywhere. docker_image=docker_image or 'python:3.8')