Esempio n. 1
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')
                   })
         ])
Esempio n. 2
0
 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')
                 })
         ])
Esempio n. 3
0
 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'),
                   })
         ])
Esempio n. 4
0
def test_FUNC_constructor_WITH_various_parameters_EXPECT_layer_created():
    """
    Test whether the layer can be created.

    :return: No return.
    """
    layer = Layer(Stack(App(), 'Test'), 'Test')
    assert layer is not None
    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):
     super().__init__(
         scope=scope,
         id=f'{TestingStack.global_prefix()}TestingFunction2',
         code=Code.from_inline('def handler(*args, **kwargs): return 200'),
         handler='index.handler',
         runtime=Runtime.PYTHON_3_6,
         layers=[Layer(scope=scope, name=f'{TestingStack.global_prefix()}TestingLayer2')]
     )
    def __init__(self, scope: Stack, name: str) -> None:
        """
        Constructor.

        :param scope: A scope in which this resource should be added.
        :param name: Name and an id of the lambda layer.
        """
        if LayerSingleton.__lock:
            raise Exception(
                'You are not allowed to call constructor. Call get_instance method.'
            )

        self.__layer = Layer(scope, name)
 def __init__(self, scope: Stack):
     super().__init__(
         scope=scope,
         id=f'{TestingStack.global_prefix()}TestingFunction4',
         code=Code.from_inline(
             'from b_lambda_layer_common.util.skip_invocation import skip_invocation\n'
             '\n\n'
             '@skip_invocation(determinator="heartbeat")\n'
             'def handler(event, context):\n'
             '    return event'
         ),
         handler='index.handler',
         runtime=Runtime.PYTHON_3_6,
         layers=[Layer(scope=scope, name=f'{TestingStack.global_prefix()}TestingLayer4')]
     )