Exemplo n.º 1
0
    def test_wsgi_script_name_on_test_request(self):
        """
        Ensure that requests sent by the "Send test request" button behaves
        sensibly
        """
        lh = LambdaHandler("tests.test_wsgi_script_name_settings")

        event = {
            "body": "",
            "resource": "/{proxy+}",
            "requestContext": {},
            "queryStringParameters": {},
            "headers": {},
            "pathParameters": {
                "proxy": "return/request/url"
            },
            "httpMethod": "GET",
            "stageVariables": {},
            "path": "/return/request/url",
        }
        response = lh.handler(event, None)

        self.assertEqual(response["statusCode"], 200)
        self.assertEqual(response["body"],
                         "https://zappa:80/return/request/url")
Exemplo n.º 2
0
    def test_wsgi_script_name_with_multi_value_header(self):
        """
        Ensure that requests generated with multivalued headers (such as
        from an ALB with Multi Valued Headers enabled) succeed.
        """
        lh = LambdaHandler("tests.test_wsgi_script_name_settings")

        event = {
            "body": "",
            "resource": "/{proxy+}",
            "requestContext": {},
            "queryStringParameters": {},
            "multiValueHeaders": {
                "Host": ["example.com"],
            },
            "pathParameters": {
                "proxy": "return/request/url"
            },
            "httpMethod": "GET",
            "stageVariables": {},
            "path": "/return/request/url",
        }
        response = lh.handler(event, None)
        self.assertEqual(response["statusCode"], 200)
        self.assertIn("multiValueHeaders", response)
Exemplo n.º 3
0
    def test_wsgi_script_name_on_test_request(self):
        """
        Ensure that requests sent by the "Send test request" button behaves
        sensibly
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'queryStringParameters': {},
            'headers': {},
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(response['body'],
                         'https://zappa:80/return/request/url')
Exemplo n.º 4
0
    def test_exception_handler_on_web_request(self):
        """
        Ensure that app exceptions triggered by web requests use the exception_handler.
        """
        lh = LambdaHandler('tests.test_exception_handler_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'queryStringParameters': {},
            'headers': {
                'Host': '1234567890.execute-api.us-east-1.amazonaws.com',
            },
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }

        mocked_exception_handler.assert_not_called()
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 500)
        mocked_exception_handler.assert_called()
Exemplo n.º 5
0
    def test_exception_in_bot_triggered_event(self):
        """
        Ensure that bot triggered exceptions are handled as defined in the settings.
        """
        lh = LambdaHandler('tests.test_bot_exception_handler_settings')
        # from : https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-lex
        event = {
            "messageVersion": "1.0",
            "invocationSource": "DialogCodeHook",
            "userId": "user-id specified in the POST request to Amazon Lex.",
            "sessionAttributes": {
                "key1": "value1",
                "key2": "value2",
            },
            "bot": {
                "name": "bot-name",
                "alias": "bot-alias",
                "version": "bot-version"
            },
            "outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
            "currentIntent": {
                "name": "intent-name",
                "slots": {
                    "slot-name": "value",
                    "slot-name": "value",
                    "slot-name": "value"
                },
                "confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
            }
        }

        response = lh.lambda_handler(event, None)
        mocked_exception_handler.assert_called
Exemplo n.º 6
0
    def test_wsgi_script_name_with_multi_value_querystring(self):
        """
        Ensure that requests generated with multivalue querystrings succeed.
        """
        lh = LambdaHandler("tests.test_wsgi_script_name_settings")

        event = {
            "body": "",
            "resource": "/{proxy+}",
            "requestContext": {},
            "multiValueQueryStringParameters": {"multi": ["value", "qs"]},
            "multiValueHeaders": {
                "Host": ["example.com"],
            },
            "pathParameters": {"proxy": "return/request/url"},
            "httpMethod": "GET",
            "stageVariables": {},
            "path": "/return/request/url",
        }
        response = lh.handler(event, None)

        self.assertEqual(response["statusCode"], 200)
        self.assertEqual(
            response["body"],
            "https://example.com/return/request/url?multi=value&multi=qs",
        )
Exemplo n.º 7
0
    def test_handler(self, session):
        # Init will test load_remote_settings
        lh = LambdaHandler('test_settings', session=session)

        # Annoyingly, this will fail during record, but
        # the result will actually be okay to use in playback.
        # See: https://github.com/garnaat/placebo/issues/48
        self.assertEqual(os.environ['hello'], 'world')

        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {   
                    u'account': u'72333333333', 
                    u'region': u'us-east-1', 
                    u'detail': {}, 
                    u'detail-type': u'Scheduled Event', 
                    u'source': u'aws.events', 
                    u'version': u'0', 
                    u'time': u'2016-05-10T21:05:39Z', 
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55', 
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        lh.handler(event, None)
Exemplo n.º 8
0
    def test_wsgi_script_name_on_domain_url(self):
        """
        Ensure that requests to the amazonaws.com host for an API with a
        domain have the correct request.url
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'queryStringParameters': {},
            'headers': {
                'Host': 'example.com',
            },
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(response['body'],
                         'https://example.com/return/request/url')
Exemplo n.º 9
0
    def test_wsgi_script_on_cognito_event_request(self):
        """
        Ensure that requests sent by cognito behave sensibly
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'version': '1',
            'region': 'eu-west-1',
            'userPoolId': 'region_poolID',
            'userName': '******',
            'callerContext': {
                'awsSdkVersion': 'aws-sdk-js-2.149.0',
                'clientId': 'client-id-here'
            },
            'triggerSource': 'PreSignUp_SignUp',
            'request': {
                'userAttributes': {
                    'email': '*****@*****.**'
                },
                'validationData': None
            },
            'response': {
                'autoConfirmUser': False,
                'autoVerifyEmail': False,
                'autoVerifyPhone': False
            }
        }

        response = lh.handler(event, None)

        self.assertEqual(response['response']['autoConfirmUser'], False)
Exemplo n.º 10
0
    def test_wsgi_script_name_on_aws_url(self):
        """
        Ensure that requests to the amazonaws.com host for an API with a
        domain have the correct request.url
        """
        lh = LambdaHandler("tests.test_wsgi_script_name_settings")

        event = {
            "body": "",
            "resource": "/{proxy+}",
            "requestContext": {},
            "queryStringParameters": {},
            "headers": {
                "Host": "1234567890.execute-api.us-east-1.amazonaws.com",
            },
            "pathParameters": {"proxy": "return/request/url"},
            "httpMethod": "GET",
            "stageVariables": {},
            "path": "/return/request/url",
        }
        response = lh.handler(event, None)

        self.assertEqual(response["statusCode"], 200)
        self.assertEqual(
            response["body"],
            "https://1234567890.execute-api.us-east-1.amazonaws.com/dev/return/request/url",
        )
Exemplo n.º 11
0
    def test_exception_handler_on_web_request(self):
        """
        Ensure that app exceptions triggered by web requests use the exception_handler.
        """
        lh = LambdaHandler("tests.test_exception_handler_settings")

        event = {
            "body": "",
            "resource": "/{proxy+}",
            "requestContext": {},
            "queryStringParameters": {},
            "headers": {
                "Host": "1234567890.execute-api.us-east-1.amazonaws.com",
            },
            "pathParameters": {"proxy": "return/request/url"},
            "httpMethod": "GET",
            "stageVariables": {},
            "path": "/return/request/url",
        }

        mocked_exception_handler.assert_not_called()
        response = lh.handler(event, None)

        self.assertEqual(response["statusCode"], 500)
        mocked_exception_handler.assert_called()
Exemplo n.º 12
0
    def test_wsgi_script_on_cognito_event_request(self):
        """
        Ensure that requests sent by cognito behave sensibly
        """
        lh = LambdaHandler("tests.test_wsgi_script_name_settings")

        event = {
            "version": "1",
            "region": "eu-west-1",
            "userPoolId": "region_poolID",
            "userName": "******",
            "callerContext": {
                "awsSdkVersion": "aws-sdk-js-2.149.0",
                "clientId": "client-id-here",
            },
            "triggerSource": "PreSignUp_SignUp",
            "request": {
                "userAttributes": {"email": "*****@*****.**"},
                "validationData": None,
            },
            "response": {
                "autoConfirmUser": False,
                "autoVerifyEmail": False,
                "autoVerifyPhone": False,
            },
        }

        response = lh.handler(event, None)

        self.assertEqual(response["response"]["autoConfirmUser"], False)
Exemplo n.º 13
0
    def test_exception_in_bot_triggered_event(self):
        """
        Ensure that bot triggered exceptions are handled as defined in the settings.
        """
        lh = LambdaHandler("tests.test_bot_exception_handler_settings")
        # from : https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-lex
        event = {
            "messageVersion": "1.0",
            "invocationSource": "DialogCodeHook",
            "userId": "user-id specified in the POST request to Amazon Lex.",
            "sessionAttributes": {
                "key1": "value1",
                "key2": "value2",
            },
            "bot": {"name": "bot-name", "alias": "bot-alias", "version": "bot-version"},
            "outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
            "currentIntent": {
                "name": "intent-name",
                "slots": {
                    "slot-name": "value",
                    "slot-name": "value",
                    "slot-name": "value",
                },
                "confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)",
            },
        }

        response = lh.lambda_handler(event, None)
        mocked_exception_handler.assert_called
Exemplo n.º 14
0
    def test_exception_handler_on_web_request(self):
        """
        Ensure that app exceptions triggered by web requests use the exception_handler.
        """
        lh = LambdaHandler('tests.test_exception_handler_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'queryStringParameters': {},
            'headers': {
                'Host': '1234567890.execute-api.us-east-1.amazonaws.com',
            },
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }

        mocked_exception_handler.assert_not_called()
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 500)
        mocked_exception_handler.assert_called()
Exemplo n.º 15
0
    def test_handler(self):
        lh = LambdaHandler('test_settings')
        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {   
                    u'account': u'72333333333', 
                    u'region': u'us-east-1', 
                    u'detail': {}, 
                    u'detail-type': u'Scheduled Event', 
                    u'source': u'aws.events', 
                    u'version': u'0', 
                    u'time': u'2016-05-10T21:05:39Z', 
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55', 
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        lh.handler(event, None)
Exemplo n.º 16
0
    def test_no_api_gw(self, session):
        lh = LambdaHandler('test_settings', session=session)
        lh.settings.USE_APIGATEWAY = False
        lh.settings.APP_FUNCTION = 'no_api_gw'

        # Test with disabled API GW (https://github.com/Miserlou/Zappa/issues/695)
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'detail-type':
            u'No API GW',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        ret = lh.handler(event, 'context')
        self.assertEquals(u'72333333333', ret[0][u'account'])
        self.assertEquals(u'No API GW', ret[0][u'detail-type'])
        self.assertEquals('context', ret[1])
Exemplo n.º 17
0
    def test_wsgi_script_name_on_domain_url(self):
        """
        Ensure that requests to the amazonaws.com host for an API with a
        domain have the correct request.url
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'queryStringParameters': {},
            'headers': {
                'Host': 'example.com',
            },
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(
            response['body'],
            'https://example.com/return/request/url'
        )
Exemplo n.º 18
0
    def test_wsgi_script_name_with_multi_value_header(self):
        """
        Ensure that requests generated with multivalued headers (such as
        from an ALB with Multi Valued Headers enabled) succeed.
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'queryStringParameters': {},
            'multiValueHeaders': {
                'Host': ['example.com'],
            },
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }
        response = lh.handler(event, None)
        self.assertEqual(response['statusCode'], 200)
        self.assertIn('multiValueHeaders', response)
Exemplo n.º 19
0
    def test_wsgi_script_name_on_test_request(self):
        """
        Ensure that requests sent by the "Send test request" button behaves
        sensibly
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'queryStringParameters': {},
            'headers': {},
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(
            response['body'],
            'https://zappa:80/return/request/url'
        )
Exemplo n.º 20
0
    def test_wsgi_script_name_with_multi_value_querystring(self):
        """
        Ensure that requests generated with multivalue querystrings succeed.
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'body': '',
            'resource': '/{proxy+}',
            'requestContext': {},
            'multiValueQueryStringParameters': {
                'multi': ['value', 'qs']
            },
            'multiValueHeaders': {
                'Host': ['example.com'],
            },
            'pathParameters': {
                'proxy': 'return/request/url'
            },
            'httpMethod': 'GET',
            'stageVariables': {},
            'path': '/return/request/url'
        }
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(
            response['body'],
            'https://example.com/return/request/url?multi=value&multi=qs')
Exemplo n.º 21
0
 def test_handler(self):
     lh = LambdaHandler('test_settings')
     event = {
         "body": {},
         "headers": {},
         "params": {
             "parameter_1": "asdf1",
             "parameter_2": "asdf2",
         },
         "method": "GET",
         "query": {}
     }
     lh.handler(event, None)
Exemplo n.º 22
0
 def test_handler(self):
     lh = LambdaHandler('test_settings')
     event = {
         "body": {},
         "headers": {},
         "params": {
             "parameter_1": "asdf1",
             "parameter_2": "asdf2",
         },
         "method": "GET",
         "query": {}
     }
     lh.handler(event, None)
Exemplo n.º 23
0
    def test_cloudwatch_subscription_event(self):
        """
        Test that events sent in the format used by CloudWatch logs via
        subscription filters are handled properly.
        The actual payload that Lambda receives is in the following format
        { "awslogs": {"data": "BASE64ENCODED_GZIP_COMPRESSED_DATA"} }
        https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html
        """
        lh = LambdaHandler('tests.test_event_script_settings')

        event = {'awslogs': {'data': "some-data-not-important-for-test"}}
        response = lh.handler(event, None)

        self.assertEqual(response, True)
Exemplo n.º 24
0
 def test_run_fuction_with_type_hint(self):
     python_version = sys.version_info[0]
     # type hints are python 3 only
     if python_version == 3:
         scope = {}
         exec('def f_with_type_hint() -> None: return', scope)
         f_with_type_hint = scope['f_with_type_hint']
         self.assertIsNone(LambdaHandler.run_function(f_with_type_hint, 'e', 'c'))
Exemplo n.º 25
0
 def test_run_fuction_with_type_hint(self):
     python_version = sys.version_info[0]
     # type hints are python 3 only
     if python_version == 3:
         scope = {}
         exec('def f_with_type_hint() -> None: return', scope)
         f_with_type_hint = scope['f_with_type_hint']
         self.assertIsNone(LambdaHandler.run_function(f_with_type_hint, 'e', 'c'))
Exemplo n.º 26
0
    def test_wsgi_script_name_on_alb_event(self):
        """
        Ensure ALB-triggered events are properly handled by LambdaHandler
        ALB-forwarded events have a slightly different request structure than API-Gateway
        https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
        """
        lh = LambdaHandler("tests.test_wsgi_script_name_settings")

        event = {
            "requestContext": {
                "elb": {
                    "targetGroupArn":
                    "arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-target-group/6d0ecf831eec9f09"
                }
            },
            "httpMethod": "GET",
            "path": "/return/request/url",
            "queryStringParameters": {},
            "headers": {
                "accept": "text/html,application/xhtml+xml",
                "accept-language": "en-US,en;q=0.8",
                "content-type": "text/plain",
                "cookie": "cookies",
                "host": "1234567890.execute-api.us-east-1.amazonaws.com",
                "user-agent":
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)",
                "x-amzn-trace-id": "Root=1-5bdb40ca-556d8b0c50dc66f0511bf520",
                "x-forwarded-for": "72.21.198.66",
                "x-forwarded-port": "443",
                "x-forwarded-proto": "https",
            },
            "isBase64Encoded": False,
            "body": "",
        }
        response = lh.handler(event, None)

        self.assertEqual(response["statusCode"], 200)
        self.assertEqual(response["statusDescription"], "200 OK")
        self.assertEqual(response["isBase64Encoded"], False)
        self.assertEqual(
            response["body"],
            "https://1234567890.execute-api.us-east-1.amazonaws.com/return/request/url",
        )
Exemplo n.º 27
0
    def test_wsgi_script_name_on_alb_event(self):
        """
        Ensure ALB-triggered events are properly handled by LambdaHandler
        ALB-forwarded events have a slightly different request structure than API-Gateway
        https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {
            'requestContext': {
                'elb': {
                    'targetGroupArn':
                    'arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-target-group/6d0ecf831eec9f09'
                }
            },
            'httpMethod': 'GET',
            'path': '/return/request/url',
            'queryStringParameters': {},
            'headers': {
                'accept': 'text/html,application/xhtml+xml',
                'accept-language': 'en-US,en;q=0.8',
                'content-type': 'text/plain',
                'cookie': 'cookies',
                'host': '1234567890.execute-api.us-east-1.amazonaws.com',
                'user-agent':
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)',
                'x-amzn-trace-id': 'Root=1-5bdb40ca-556d8b0c50dc66f0511bf520',
                'x-forwarded-for': '72.21.198.66',
                'x-forwarded-port': '443',
                'x-forwarded-proto': 'https'
            },
            'isBase64Encoded': False,
            'body': ''
        }
        response = lh.handler(event, None)

        self.assertEqual(response['statusCode'], 200)
        self.assertEqual(response['statusDescription'], '200 OK')
        self.assertEqual(response['isBase64Encoded'], False)
        self.assertEqual(
            response['body'],
            'https://1234567890.execute-api.us-east-1.amazonaws.com/return/request/url'
        )
Exemplo n.º 28
0
    def test_wsgi_script_on_cognito_event_request(self):
        """
        Ensure that requests sent by cognito behave sensibly
        """
        lh = LambdaHandler('tests.test_wsgi_script_name_settings')

        event = {'version': '1',
                 'region': 'eu-west-1',
                 'userPoolId': 'region_poolID',
                 'userName': '******',
                 'callerContext': {'awsSdkVersion': 'aws-sdk-js-2.149.0',
                                   'clientId': 'client-id-here'},
                 'triggerSource': 'PreSignUp_SignUp',
                 'request': {'userAttributes':
                             {'email': '*****@*****.**'}, 'validationData': None},
                 'response': {'autoConfirmUser': False,
                              'autoVerifyEmail': False,
                              'autoVerifyPhone': False}}

        response = lh.handler(event, None)

        self.assertEqual(response['response']['autoConfirmUser'], False)
Exemplo n.º 29
0
    def test_run_function(self):
        self.assertIsNone(LambdaHandler.run_function(no_args, 'e', 'c'))
        self.assertEqual(LambdaHandler.run_function(one_arg, 'e', 'c'), 'e')
        self.assertEqual(LambdaHandler.run_function(two_args, 'e', 'c'), ('e', 'c'))
        self.assertEqual(LambdaHandler.run_function(var_args, 'e', 'c'), ('e', 'c'))
        self.assertEqual(LambdaHandler.run_function(var_args_with_one, 'e', 'c'), ('e', 'c'))

        try:
            LambdaHandler.run_function(unsupported, 'e', 'c')
            self.fail('Exception expected')
        except RuntimeError as e:
            pass
Exemplo n.º 30
0
    def test_run_function(self):
        self.assertIsNone(LambdaHandler.run_function(no_args, 'e', 'c'))
        self.assertEqual(LambdaHandler.run_function(one_arg, 'e', 'c'), 'e')
        self.assertEqual(LambdaHandler.run_function(two_args, 'e', 'c'), ('e', 'c'))
        self.assertEqual(LambdaHandler.run_function(var_args, 'e', 'c'), ('e', 'c'))
        self.assertEqual(LambdaHandler.run_function(var_args_with_one, 'e', 'c'), ('e', 'c'))

        try:
            LambdaHandler.run_function(unsupported, 'e', 'c')
            self.fail('Exception expected')
        except RuntimeError as e:
            pass
Exemplo n.º 31
0
    def test_aws_connect_triggered_event(self):
        """
        Ensure that AWS triggered events are handled as in the settings
        """
        lh = LambdaHandler('tests.test_connect_handler_being_triggered')
        # from : https://docs.aws.amazon.com/connect/latest/adminguide/connect-lambda-functions.html
        event = {
            "Details": {
                "ContactData": {
                    "Attributes": {},
                    "Channel": "VOICE",
                    "ContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
                    "CustomerEndpoint": {
                        "Address": "+1234567890",
                        "Type": "TELEPHONE_NUMBER"
                    },
                    "InitialContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
                    "InitiationMethod": "INBOUND | OUTBOUND | TRANSFER | CALLBACK",
                    "InstanceARN": "arn:aws:connect:aws-region:1234567890:instance/c8c0e68d-2200-4265-82c0-XXXXXXXXXX",
                    "PreviousContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXX",
                    "Queue": "QueueName",
                    "SystemEndpoint": {
                        "Address": "+1234567890",
                        "Type": "TELEPHONE_NUMBER"
                    }
                },
                "Parameters": {
                    "sentAttributeKey": "sentAttributeValue"
                }
            },
            "Name": "ContactFlowEvent"
        }

        response = lh.handler(event, None)

        self.assertEqual(response, 'Success')
Exemplo n.º 32
0
    def test_run_function(self):
        self.assertIsNone(LambdaHandler.run_function(no_args, "e", "c"))
        self.assertEqual(LambdaHandler.run_function(one_arg, "e", "c"), "e")
        self.assertEqual(LambdaHandler.run_function(two_args, "e", "c"), ("e", "c"))
        self.assertEqual(LambdaHandler.run_function(var_args, "e", "c"), ("e", "c"))
        self.assertEqual(
            LambdaHandler.run_function(var_args_with_one, "e", "c"), ("e", "c")
        )

        try:
            LambdaHandler.run_function(unsupported, "e", "c")
            self.fail("Exception expected")
        except RuntimeError as e:
            pass
Exemplo n.º 33
0
    def test_handler(self, session):
        # Init will test load_remote_settings
        lh = LambdaHandler('test_settings', session=session)

        # Annoyingly, this will fail during record, but
        # the result will actually be okay to use in playback.
        # See: https://github.com/garnaat/placebo/issues/48
        self.assertEqual(os.environ['hello'], 'world')

        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'detail-type':
            u'Scheduled Event',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)
Exemplo n.º 34
0
    def test_handler(self):
        lh = LambdaHandler('test_settings')
        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'detail-type':
            u'Scheduled Event',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)
Exemplo n.º 35
0
    def test_handler(self, session):
        # Init will test load_remote_settings
        lh = LambdaHandler('test_settings', session=session)

        # Annoyingly, this will fail during record, but
        # the result will actually be okay to use in playback.
        # See: https://github.com/garnaat/placebo/issues/48
        self.assertEqual(os.environ['hello'], 'world')

        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'detail-type': u'Scheduled Event',
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        lh.handler(event, None)

        # Test command event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'command': u'test_settings.command',
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        lh.handler(event, None)

        # Test AWS S3 event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'Records': [{'s3': {'configurationId': 'test_settings.aws_s3_event'}}],
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        self.assertEqual("AWS S3 EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            u'account': u'72333333333',
            u'region': u'us-east-1',
            u'detail': {},
            u'Records': [
                {
                    u'EventVersion': u'1.0',
                    u'EventSource': u'aws:sns',
                    u'EventSubscriptionArn': u'arn:aws:sns:EXAMPLE',
                    u'Sns': {
                        u'SignatureVersion': u'1',
                        u'Timestamp': u'1970-01-01T00:00:00.000Z',
                        u'Signature': u'EXAMPLE',
                        u'SigningCertUrl': u'EXAMPLE',
                        u'MessageId': u'95df01b4-ee98-5cb9-9903-4c221d41eb5e',
                        u'Message': u'Hello from SNS!',
                        u'Subject': u'TestInvoke',
                        u'Type': u'Notification',
                        u'UnsubscribeUrl': u'EXAMPLE',
                        u'TopicArn': u'arn:aws:sns:1',
                        u'MessageAttributes': {
                            u'Test': {u'Type': u'String', u'Value': u'TestString'},
                            u'TestBinary': {u'Type': u'Binary', u'Value': u'TestBinary'}
                        }
                    }
                }
            ]
        }
        self.assertEqual("AWS SNS EVENT", lh.handler(event, None))

        # Test AWS DynamoDB event
        event = {
            u'Records': [
                {
                    u'eventID': u'1',
                    u'eventVersion': u'1.0',
                    u'dynamodb': {
                        u'Keys': {u'Id': {u'N': u'101'}},
                        u'NewImage': {u'Message': {u'S': u'New item!'}, u'Id': {u'N': u'101'}},
                        u'StreamViewType': u'NEW_AND_OLD_IMAGES',
                        u'SequenceNumber': u'111', u'SizeBytes': 26
                    },
                    u'awsRegion': u'us-west-2',
                    u'eventName': u'INSERT',
                    u'eventSourceARN': u'arn:aws:dynamodb:1',
                    u'eventSource': u'aws:dynamodb'
                }
            ]
        }
        self.assertEqual("AWS DYNAMODB EVENT", lh.handler(event, None))

        # Test AWS kinesis event
        event = {
            u'Records': [
                {
                    u'eventID': u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                    u'eventVersion': u'1.0',
                    u'kinesis': {
                        u'partitionKey': u'partitionKey-3',
                        u'data': u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                        u'kinesisSchemaVersion': u'1.0',
                        u'sequenceNumber': u'49545115243490985018280067714973144582180062593244200961'
                    },
                    u'invokeIdentityArn': u'arn:aws:iam::EXAMPLE',
                    u'eventName': u'aws:kinesis:record',
                    u'eventSourceARN': u'arn:aws:kinesis:1',
                    u'eventSource': u'aws:kinesis',
                    u'awsRegion': u'us-east-1'
                 }
            ]
        }
        self.assertEqual("AWS KINESIS EVENT", lh.handler(event, None))

        # Unhandled event
        event = {
            u'Records': [
                {
                    u'eventID': u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                    u'eventVersion': u'1.0',
                    u'kinesis': {
                        u'partitionKey': u'partitionKey-3',
                        u'data': u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                        u'kinesisSchemaVersion': u'1.0',
                        u'sequenceNumber': u'49545115243490985018280067714973144582180062593244200961'
                    },
                    u'eventSourceARN': u'bad:arn:1',
                }
            ]
        }
        self.assertIsNone(lh.handler(event, None))
Exemplo n.º 36
0
    def test_handler(self, session):
        # Init will test load_remote_settings
        lh = LambdaHandler('test_settings', session=session)

        # Annoyingly, this will fail during record, but
        # the result will actually be okay to use in playback.
        # See: https://github.com/garnaat/placebo/issues/48
        self.assertEqual(os.environ['hello'], 'world')

        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'detail-type':
            u'Scheduled Event',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)

        # Test command event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'command':
            u'test_settings.command',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)

        # Test command for async event
        event = {
            u'account': u'72333333333',
            u'region': u'us-east-1',
            u'detail': {},
            u'command': u'zappa.asynchronous.route_lambda_task',
            u'task_path': u'tests.test_app.async_me',
            u'args': [u'xxx'],
            u'kwargs': {},
            u'source': u'aws.events',
            u'version': u'0',
            u'time': u'2016-05-10T21:05:39Z',
            u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
        }
        self.assertEqual('run async when on lambda xxx',
                         lh.handler(event, None))
        event[u'kwargs'] = {'foo': 'bar'}
        self.assertEqual('run async when on lambda xxxbar',
                         lh.handler(event, None))

        # Test raw_command event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'raw_command':
            u'print("check one two")',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)

        # Test AWS S3 event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'Records': [{
                's3': {
                    'configurationId':
                    'test_project:test_settings.aws_s3_event'
                }
            }],
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        self.assertEqual("AWS S3 EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'Records': [{
                u'EventVersion': u'1.0',
                u'EventSource': u'aws:sns',
                u'EventSubscriptionArn': u'arn:aws:sns:EXAMPLE',
                u'Sns': {
                    u'SignatureVersion': u'1',
                    u'Timestamp': u'1970-01-01T00:00:00.000Z',
                    u'Signature': u'EXAMPLE',
                    u'SigningCertUrl': u'EXAMPLE',
                    u'MessageId': u'95df01b4-ee98-5cb9-9903-4c221d41eb5e',
                    u'Message': u'Hello from SNS!',
                    u'Subject': u'TestInvoke',
                    u'Type': u'Notification',
                    u'UnsubscribeUrl': u'EXAMPLE',
                    u'TopicArn': u'arn:aws:sns:1',
                    u'MessageAttributes': {
                        u'Test': {
                            u'Type': u'String',
                            u'Value': u'TestString'
                        },
                        u'TestBinary': {
                            u'Type': u'Binary',
                            u'Value': u'TestBinary'
                        }
                    }
                }
            }]
        }
        self.assertEqual("AWS SNS EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'Records': [{
                u'EventVersion': u'1.0',
                u'EventSource': u'aws:sns',
                u'EventSubscriptionArn': u'arn:aws:sns:EXAMPLE',
                u'Sns': {
                    u'SignatureVersion':
                    u'1',
                    u'Timestamp':
                    u'1970-01-01T00:00:00.000Z',
                    u'Signature':
                    u'EXAMPLE',
                    u'SigningCertUrl':
                    u'EXAMPLE',
                    u'MessageId':
                    u'95df01b4-ee98-5cb9-9903-4c221d41eb5e',
                    u'Message':
                    u'{"args": ["arg1", "arg2"], "command": "zappa.asynchronous.route_sns_task", '
                    u'"task_path": "test_settings.aws_async_sns_event", "kwargs": {"arg3": "varg3"}}',
                    u'Subject':
                    u'TestInvoke',
                    u'Type':
                    u'Notification',
                    u'UnsubscribeUrl':
                    u'EXAMPLE',
                    u'MessageAttributes': {
                        u'Test': {
                            u'Type': u'String',
                            u'Value': u'TestString'
                        },
                        u'TestBinary': {
                            u'Type': u'Binary',
                            u'Value': u'TestBinary'
                        }
                    }
                }
            }]
        }
        self.assertEqual("AWS ASYNC SNS EVENT", lh.handler(event, None))

        # Test AWS DynamoDB event
        event = {
            u'Records': [{
                u'eventID': u'1',
                u'eventVersion': u'1.0',
                u'dynamodb': {
                    u'Keys': {
                        u'Id': {
                            u'N': u'101'
                        }
                    },
                    u'NewImage': {
                        u'Message': {
                            u'S': u'New item!'
                        },
                        u'Id': {
                            u'N': u'101'
                        }
                    },
                    u'StreamViewType': u'NEW_AND_OLD_IMAGES',
                    u'SequenceNumber': u'111',
                    u'SizeBytes': 26
                },
                u'awsRegion': u'us-west-2',
                u'eventName': u'INSERT',
                u'eventSourceARN': u'arn:aws:dynamodb:1',
                u'eventSource': u'aws:dynamodb'
            }]
        }
        self.assertEqual("AWS DYNAMODB EVENT", lh.handler(event, None))

        # Test AWS kinesis event
        event = {
            u'Records': [{
                u'eventID':
                u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                u'eventVersion': u'1.0',
                u'kinesis': {
                    u'partitionKey':
                    u'partitionKey-3',
                    u'data':
                    u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                    u'kinesisSchemaVersion':
                    u'1.0',
                    u'sequenceNumber':
                    u'49545115243490985018280067714973144582180062593244200961'
                },
                u'invokeIdentityArn': u'arn:aws:iam::EXAMPLE',
                u'eventName': u'aws:kinesis:record',
                u'eventSourceARN': u'arn:aws:kinesis:1',
                u'eventSource': u'aws:kinesis',
                u'awsRegion': u'us-east-1'
            }]
        }
        self.assertEqual("AWS KINESIS EVENT", lh.handler(event, None))

        # Test AWS SQS event
        event = {
            u"Records": [{
                u"messageId": u"c80e8021-a70a-42c7-a470-796e1186f753",
                u"receiptHandle":
                u"AQEBJQ+/u6NsnT5t8Q/VbVxgdUl4TMKZ5FqhksRdIQvLBhwNvADoBxYSOVeCBXdnS9P+erlTtwEALHsnBXynkfPLH3BOUqmgzP25U8kl8eHzq6RAlzrSOfTO8ox9dcp6GLmW33YjO3zkq5VRYyQlJgLCiAZUpY2D4UQcE5D1Vm8RoKfbE+xtVaOctYeINjaQJ1u3mWx9T7tork3uAlOe1uyFjCWU5aPX/1OHhWCGi2EPPZj6vchNqDOJC/Y2k1gkivqCjz1CZl6FlZ7UVPOx3AMoszPuOYZ+Nuqpx2uCE2MHTtMHD8PVjlsWirt56oUr6JPp9aRGo6bitPIOmi4dX0FmuMKD6u/JnuZCp+AXtJVTmSHS8IXt/twsKU7A+fiMK01NtD5msNgVPoe9JbFtlGwvTQ==",
                u"body": u"{\"foo\":\"bar\"}",
                u"attributes": {
                    u"ApproximateReceiveCount": u"3",
                    u"SentTimestamp": u"1529104986221",
                    u"SenderId": u"594035263019",
                    u"ApproximateFirstReceiveTimestamp": u"1529104986230"
                },
                u"messageAttributes": {},
                u"md5OfBody": u"9bb58f26192e4ba00f01e2e7b136bbd8",
                u"eventSource": u"aws:sqs",
                u"eventSourceARN": u"arn:aws:sqs:1",
                u"awsRegion": u"us-east-1"
            }]
        }
        self.assertEqual("AWS SQS EVENT", lh.handler(event, None))

        # Test Authorizer event
        event = {
            u'authorizationToken': u'hubtoken1',
            u'methodArn':
            u'arn:aws:execute-api:us-west-2:1234:xxxxx/dev/GET/v1/endpoint/param',
            u'type': u'TOKEN'
        }
        self.assertEqual("AUTHORIZER_EVENT", lh.handler(event, None))

        # Ensure Zappa does return 401 if no function was defined.
        lh.settings.AUTHORIZER_FUNCTION = None
        with self.assertRaisesRegexp(Exception, 'Unauthorized'):
            lh.handler(event, None)

        # Unhandled event
        event = {
            u'Records': [{
                u'eventID':
                u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                u'eventVersion': u'1.0',
                u'kinesis': {
                    u'partitionKey':
                    u'partitionKey-3',
                    u'data':
                    u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                    u'kinesisSchemaVersion':
                    u'1.0',
                    u'sequenceNumber':
                    u'49545115243490985018280067714973144582180062593244200961'
                },
                u'eventSourceARN': u'bad:arn:1',
            }]
        }
        self.assertIsNone(lh.handler(event, None))
Exemplo n.º 37
0
    def test_handler(self, session):
        # Init will test load_remote_settings
        lh = LambdaHandler('test_settings', session=session)

        # Annoyingly, this will fail during record, but
        # the result will actually be okay to use in playback.
        # See: https://github.com/garnaat/placebo/issues/48
        self.assertEqual(os.environ['hello'], 'world')

        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'detail-type':
            u'Scheduled Event',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)

        # Test command event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'command':
            u'test_settings.command',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)

        # Test command for async event
        event = {
            u'account': u'72333333333',
            u'region': u'us-east-1',
            u'detail': {},
            u'command': u'zappa.async.route_lambda_task',
            u'task_path': u'tests.test_app.async_me',
            u'args': [u'xxx'],
            u'kwargs': {},
            u'source': u'aws.events',
            u'version': u'0',
            u'time': u'2016-05-10T21:05:39Z',
            u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
        }
        self.assertEqual('run async when on lambda xxx',
                         lh.handler(event, None))
        event[u'kwargs'] = {'foo': 'bar'}
        self.assertEqual('run async when on lambda xxxbar',
                         lh.handler(event, None))

        # Test raw_command event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'raw_command':
            u'print("check one two")',
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        lh.handler(event, None)

        # Test AWS S3 event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'Records': [{
                's3': {
                    'configurationId': 'test_settings.aws_s3_event'
                }
            }],
            u'source':
            u'aws.events',
            u'version':
            u'0',
            u'time':
            u'2016-05-10T21:05:39Z',
            u'id':
            u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
            u'resources': [
                u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me'
            ]
        }
        self.assertEqual("AWS S3 EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            u'account':
            u'72333333333',
            u'region':
            u'us-east-1',
            u'detail': {},
            u'Records': [{
                u'EventVersion': u'1.0',
                u'EventSource': u'aws:sns',
                u'EventSubscriptionArn': u'arn:aws:sns:EXAMPLE',
                u'Sns': {
                    u'SignatureVersion': u'1',
                    u'Timestamp': u'1970-01-01T00:00:00.000Z',
                    u'Signature': u'EXAMPLE',
                    u'SigningCertUrl': u'EXAMPLE',
                    u'MessageId': u'95df01b4-ee98-5cb9-9903-4c221d41eb5e',
                    u'Message': u'Hello from SNS!',
                    u'Subject': u'TestInvoke',
                    u'Type': u'Notification',
                    u'UnsubscribeUrl': u'EXAMPLE',
                    u'TopicArn': u'arn:aws:sns:1',
                    u'MessageAttributes': {
                        u'Test': {
                            u'Type': u'String',
                            u'Value': u'TestString'
                        },
                        u'TestBinary': {
                            u'Type': u'Binary',
                            u'Value': u'TestBinary'
                        }
                    }
                }
            }]
        }
        self.assertEqual("AWS SNS EVENT", lh.handler(event, None))

        # Test AWS DynamoDB event
        event = {
            u'Records': [{
                u'eventID': u'1',
                u'eventVersion': u'1.0',
                u'dynamodb': {
                    u'Keys': {
                        u'Id': {
                            u'N': u'101'
                        }
                    },
                    u'NewImage': {
                        u'Message': {
                            u'S': u'New item!'
                        },
                        u'Id': {
                            u'N': u'101'
                        }
                    },
                    u'StreamViewType': u'NEW_AND_OLD_IMAGES',
                    u'SequenceNumber': u'111',
                    u'SizeBytes': 26
                },
                u'awsRegion': u'us-west-2',
                u'eventName': u'INSERT',
                u'eventSourceARN': u'arn:aws:dynamodb:1',
                u'eventSource': u'aws:dynamodb'
            }]
        }
        self.assertEqual("AWS DYNAMODB EVENT", lh.handler(event, None))

        # Test AWS kinesis event
        event = {
            u'Records': [{
                u'eventID':
                u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                u'eventVersion': u'1.0',
                u'kinesis': {
                    u'partitionKey':
                    u'partitionKey-3',
                    u'data':
                    u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                    u'kinesisSchemaVersion':
                    u'1.0',
                    u'sequenceNumber':
                    u'49545115243490985018280067714973144582180062593244200961'
                },
                u'invokeIdentityArn': u'arn:aws:iam::EXAMPLE',
                u'eventName': u'aws:kinesis:record',
                u'eventSourceARN': u'arn:aws:kinesis:1',
                u'eventSource': u'aws:kinesis',
                u'awsRegion': u'us-east-1'
            }]
        }
        self.assertEqual("AWS KINESIS EVENT", lh.handler(event, None))

        # Test Authorizer event
        event = {
            u'authorizationToken': u'hubtoken1',
            u'methodArn':
            u'arn:aws:execute-api:us-west-2:1234:xxxxx/dev/GET/v1/endpoint/param',
            u'type': u'TOKEN'
        }
        self.assertEqual("AUTHORIZER_EVENT", lh.handler(event, None))

        # Ensure Zappa does return 401 if no function was defined.
        lh.settings.AUTHORIZER_FUNCTION = None
        with self.assertRaisesRegexp(Exception, 'Unauthorized'):
            lh.handler(event, None)

        # Unhandled event
        event = {
            u'Records': [{
                u'eventID':
                u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                u'eventVersion': u'1.0',
                u'kinesis': {
                    u'partitionKey':
                    u'partitionKey-3',
                    u'data':
                    u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                    u'kinesisSchemaVersion':
                    u'1.0',
                    u'sequenceNumber':
                    u'49545115243490985018280067714973144582180062593244200961'
                },
                u'eventSourceARN': u'bad:arn:1',
            }]
        }
        self.assertIsNone(lh.handler(event, None))
Exemplo n.º 38
0
import json
from zappa.handler import LambdaHandler


def load_settings(settings_name='zappa_settings.json'):
    with open(settings_name, 'r') as f:
        return json.load(f)


# this is how zappa executes the app function
settings = load_settings()
app = LambdaHandler.import_module_and_get_function(
    settings['dev']['app_function'])

if __name__ == '__main__':
    app.run(host='0.0.0.0', port='5000', debug=True)
Exemplo n.º 39
0
 def test_run_fuction_with_type_hint(self):
     scope = {}
     exec("def f_with_type_hint() -> None: return", scope)
     f_with_type_hint = scope["f_with_type_hint"]
     self.assertIsNone(LambdaHandler.run_function(f_with_type_hint, "e", "c"))
Exemplo n.º 40
0
 def test_run_fuction_with_type_hint(self):
     scope = {}
     exec('def f_with_type_hint() -> None: return', scope)
     f_with_type_hint = scope['f_with_type_hint']
     self.assertIsNone(
         LambdaHandler.run_function(f_with_type_hint, 'e', 'c'))
Exemplo n.º 41
0
    def test_handler(self, session):
        # Init will test load_remote_settings
        lh = LambdaHandler('test_settings', session=session)

        # Annoyingly, this will fail during record, but
        # the result will actually be okay to use in playback.
        # See: https://github.com/garnaat/placebo/issues/48
        self.assertEqual(os.environ['hello'], 'world')

        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {}
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'detail-type': u'Scheduled Event',
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        lh.handler(event, None)

        # Test command event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'command': u'test_settings.command',
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        lh.handler(event, None)

        # Test command for async event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'command': u'zappa.async.route_lambda_task',
                    u'task_path': u'tests.test_app.async_me',
                    u'args': [u'xxx'],
                    u'kwargs': {},
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                }
        self.assertEqual('run async when on lambda xxx', lh.handler(event, None))
        event[u'kwargs'] = {'foo': 'bar'}
        self.assertEqual('run async when on lambda xxxbar', lh.handler(event, None))

        # Test raw_command event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'raw_command': u'print("check one two")',
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        lh.handler(event, None)

        # Test AWS S3 event
        event = {
                    u'account': u'72333333333',
                    u'region': u'us-east-1',
                    u'detail': {},
                    u'Records': [{'s3': {'configurationId': 'test_project:test_settings.aws_s3_event'}}],
                    u'source': u'aws.events',
                    u'version': u'0',
                    u'time': u'2016-05-10T21:05:39Z',
                    u'id': u'0d6a6db0-d5e7-4755-93a0-750a8bf49d55',
                    u'resources': [u'arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me']
                }
        self.assertEqual("AWS S3 EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            u'account': u'72333333333',
            u'region': u'us-east-1',
            u'detail': {},
            u'Records': [
                {
                    u'EventVersion': u'1.0',
                    u'EventSource': u'aws:sns',
                    u'EventSubscriptionArn': u'arn:aws:sns:EXAMPLE',
                    u'Sns': {
                        u'SignatureVersion': u'1',
                        u'Timestamp': u'1970-01-01T00:00:00.000Z',
                        u'Signature': u'EXAMPLE',
                        u'SigningCertUrl': u'EXAMPLE',
                        u'MessageId': u'95df01b4-ee98-5cb9-9903-4c221d41eb5e',
                        u'Message': u'Hello from SNS!',
                        u'Subject': u'TestInvoke',
                        u'Type': u'Notification',
                        u'UnsubscribeUrl': u'EXAMPLE',
                        u'TopicArn': u'arn:aws:sns:1',
                        u'MessageAttributes': {
                            u'Test': {u'Type': u'String', u'Value': u'TestString'},
                            u'TestBinary': {u'Type': u'Binary', u'Value': u'TestBinary'}
                        }
                    }
                }
            ]
        }
        self.assertEqual("AWS SNS EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            u'account': u'72333333333',
            u'region': u'us-east-1',
            u'detail': {},
            u'Records': [
                {
                    u'EventVersion': u'1.0',
                    u'EventSource': u'aws:sns',
                    u'EventSubscriptionArn': u'arn:aws:sns:EXAMPLE',
                    u'Sns': {
                        u'SignatureVersion': u'1',
                        u'Timestamp': u'1970-01-01T00:00:00.000Z',
                        u'Signature': u'EXAMPLE',
                        u'SigningCertUrl': u'EXAMPLE',
                        u'MessageId': u'95df01b4-ee98-5cb9-9903-4c221d41eb5e',
                        u'Message': u'{"args": ["arg1", "arg2"], "command": "zappa.async.route_sns_task", '
                                    u'"task_path": "test_settings.aws_async_sns_event", "kwargs": {"arg3": "varg3"}}',
                        u'Subject': u'TestInvoke',
                        u'Type': u'Notification',
                        u'UnsubscribeUrl': u'EXAMPLE',
                        u'MessageAttributes': {
                            u'Test': {u'Type': u'String', u'Value': u'TestString'},
                            u'TestBinary': {u'Type': u'Binary', u'Value': u'TestBinary'}
                        }
                    }
                }
            ]
        }
        self.assertEqual("AWS ASYNC SNS EVENT", lh.handler(event, None))

        # Test AWS DynamoDB event
        event = {
            u'Records': [
                {
                    u'eventID': u'1',
                    u'eventVersion': u'1.0',
                    u'dynamodb': {
                        u'Keys': {u'Id': {u'N': u'101'}},
                        u'NewImage': {u'Message': {u'S': u'New item!'}, u'Id': {u'N': u'101'}},
                        u'StreamViewType': u'NEW_AND_OLD_IMAGES',
                        u'SequenceNumber': u'111', u'SizeBytes': 26
                    },
                    u'awsRegion': u'us-west-2',
                    u'eventName': u'INSERT',
                    u'eventSourceARN': u'arn:aws:dynamodb:1',
                    u'eventSource': u'aws:dynamodb'
                }
            ]
        }
        self.assertEqual("AWS DYNAMODB EVENT", lh.handler(event, None))

        # Test AWS kinesis event
        event = {
            u'Records': [
                {
                    u'eventID': u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                    u'eventVersion': u'1.0',
                    u'kinesis': {
                        u'partitionKey': u'partitionKey-3',
                        u'data': u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                        u'kinesisSchemaVersion': u'1.0',
                        u'sequenceNumber': u'49545115243490985018280067714973144582180062593244200961'
                    },
                    u'invokeIdentityArn': u'arn:aws:iam::EXAMPLE',
                    u'eventName': u'aws:kinesis:record',
                    u'eventSourceARN': u'arn:aws:kinesis:1',
                    u'eventSource': u'aws:kinesis',
                    u'awsRegion': u'us-east-1'
                 }
            ]
        }
        self.assertEqual("AWS KINESIS EVENT", lh.handler(event, None))

        # Test Authorizer event
        event = {u'authorizationToken': u'hubtoken1', u'methodArn': u'arn:aws:execute-api:us-west-2:1234:xxxxx/dev/GET/v1/endpoint/param', u'type': u'TOKEN'}
        self.assertEqual("AUTHORIZER_EVENT", lh.handler(event, None))

        # Ensure Zappa does return 401 if no function was defined.
        lh.settings.AUTHORIZER_FUNCTION = None
        with self.assertRaisesRegexp(Exception, 'Unauthorized'):
            lh.handler(event, None)

        # Unhandled event
        event = {
            u'Records': [
                {
                    u'eventID': u'shardId-000000000000:49545115243490985018280067714973144582180062593244200961',
                    u'eventVersion': u'1.0',
                    u'kinesis': {
                        u'partitionKey': u'partitionKey-3',
                        u'data': u'SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=',
                        u'kinesisSchemaVersion': u'1.0',
                        u'sequenceNumber': u'49545115243490985018280067714973144582180062593244200961'
                    },
                    u'eventSourceARN': u'bad:arn:1',
                }
            ]
        }
        self.assertIsNone(lh.handler(event, None))
Exemplo n.º 42
0
    def test_handler(self, session):
        # Init will test load_remote_settings
        lh = LambdaHandler("test_settings", session=session)

        # Annoyingly, this will fail during record, but
        # the result will actually be okay to use in playback.
        # See: https://github.com/garnaat/placebo/issues/48
        self.assertEqual(os.environ["hello"], "world")

        event = {
            "body": {},
            "headers": {},
            "params": {
                "parameter_1": "asdf1",
                "parameter_2": "asdf2",
            },
            "method": "GET",
            "query": {},
        }
        lh.handler(event, None)

        # Test scheduled event
        event = {
            "account":
            "72333333333",
            "region":
            "us-east-1",
            "detail": {},
            "detail-type":
            "Scheduled Event",
            "source":
            "aws.events",
            "version":
            "0",
            "time":
            "2016-05-10T21:05:39Z",
            "id":
            "0d6a6db0-d5e7-4755-93a0-750a8bf49d55",
            "resources": [
                "arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me"
            ],
        }
        lh.handler(event, None)

        # Test command event
        event = {
            "account":
            "72333333333",
            "region":
            "us-east-1",
            "detail": {},
            "command":
            "test_settings.command",
            "source":
            "aws.events",
            "version":
            "0",
            "time":
            "2016-05-10T21:05:39Z",
            "id":
            "0d6a6db0-d5e7-4755-93a0-750a8bf49d55",
            "resources": [
                "arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me"
            ],
        }
        lh.handler(event, None)

        # Test command for async event
        event = {
            "account": "72333333333",
            "region": "us-east-1",
            "detail": {},
            "command": "zappa.asynchronous.route_lambda_task",
            "task_path": "tests.test_app.async_me",
            "args": ["xxx"],
            "kwargs": {},
            "source": "aws.events",
            "version": "0",
            "time": "2016-05-10T21:05:39Z",
            "id": "0d6a6db0-d5e7-4755-93a0-750a8bf49d55",
        }
        self.assertEqual("run async when on lambda xxx",
                         lh.handler(event, None))
        event["kwargs"] = {"foo": "bar"}
        self.assertEqual("run async when on lambda xxxbar",
                         lh.handler(event, None))

        # Test raw_command event
        event = {
            "account":
            "72333333333",
            "region":
            "us-east-1",
            "detail": {},
            "raw_command":
            'print("check one two")',
            "source":
            "aws.events",
            "version":
            "0",
            "time":
            "2016-05-10T21:05:39Z",
            "id":
            "0d6a6db0-d5e7-4755-93a0-750a8bf49d55",
            "resources": [
                "arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me"
            ],
        }
        lh.handler(event, None)

        # Test AWS S3 event
        event = {
            "account":
            "72333333333",
            "region":
            "us-east-1",
            "detail": {},
            "Records": [{
                "s3": {
                    "configurationId":
                    "test_project:test_settings.aws_s3_event"
                }
            }],
            "source":
            "aws.events",
            "version":
            "0",
            "time":
            "2016-05-10T21:05:39Z",
            "id":
            "0d6a6db0-d5e7-4755-93a0-750a8bf49d55",
            "resources": [
                "arn:aws:events:us-east-1:72333333333:rule/tests.test_app.schedule_me"
            ],
        }
        self.assertEqual("AWS S3 EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            "account":
            "72333333333",
            "region":
            "us-east-1",
            "detail": {},
            "Records": [{
                "EventVersion": "1.0",
                "EventSource": "aws:sns",
                "EventSubscriptionArn": "arn:aws:sns:EXAMPLE",
                "Sns": {
                    "SignatureVersion": "1",
                    "Timestamp": "1970-01-01T00:00:00.000Z",
                    "Signature": "EXAMPLE",
                    "SigningCertUrl": "EXAMPLE",
                    "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
                    "Message": "Hello from SNS!",
                    "Subject": "TestInvoke",
                    "Type": "Notification",
                    "UnsubscribeUrl": "EXAMPLE",
                    "TopicArn": "arn:aws:sns:1",
                    "MessageAttributes": {
                        "Test": {
                            "Type": "String",
                            "Value": "TestString"
                        },
                        "TestBinary": {
                            "Type": "Binary",
                            "Value": "TestBinary"
                        },
                    },
                },
            }],
        }
        self.assertEqual("AWS SNS EVENT", lh.handler(event, None))

        # Test AWS SNS event
        event = {
            "account":
            "72333333333",
            "region":
            "us-east-1",
            "detail": {},
            "Records": [{
                "EventVersion": "1.0",
                "EventSource": "aws:sns",
                "EventSubscriptionArn": "arn:aws:sns:EXAMPLE",
                "Sns": {
                    "SignatureVersion":
                    "1",
                    "Timestamp":
                    "1970-01-01T00:00:00.000Z",
                    "Signature":
                    "EXAMPLE",
                    "SigningCertUrl":
                    "EXAMPLE",
                    "MessageId":
                    "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
                    "Message":
                    '{"args": ["arg1", "arg2"], "command": "zappa.asynchronous.route_sns_task", '
                    '"task_path": "test_settings.aws_async_sns_event", "kwargs": {"arg3": "varg3"}}',
                    "Subject":
                    "TestInvoke",
                    "Type":
                    "Notification",
                    "UnsubscribeUrl":
                    "EXAMPLE",
                    "MessageAttributes": {
                        "Test": {
                            "Type": "String",
                            "Value": "TestString"
                        },
                        "TestBinary": {
                            "Type": "Binary",
                            "Value": "TestBinary"
                        },
                    },
                },
            }],
        }
        self.assertEqual("AWS ASYNC SNS EVENT", lh.handler(event, None))

        # Test AWS DynamoDB event
        event = {
            "Records": [{
                "eventID": "1",
                "eventVersion": "1.0",
                "dynamodb": {
                    "Keys": {
                        "Id": {
                            "N": "101"
                        }
                    },
                    "NewImage": {
                        "Message": {
                            "S": "New item!"
                        },
                        "Id": {
                            "N": "101"
                        }
                    },
                    "StreamViewType": "NEW_AND_OLD_IMAGES",
                    "SequenceNumber": "111",
                    "SizeBytes": 26,
                },
                "awsRegion": "us-west-2",
                "eventName": "INSERT",
                "eventSourceARN": "arn:aws:dynamodb:1",
                "eventSource": "aws:dynamodb",
            }]
        }
        self.assertEqual("AWS DYNAMODB EVENT", lh.handler(event, None))

        # Test AWS kinesis event
        event = {
            "Records": [{
                "eventID":
                "shardId-000000000000:49545115243490985018280067714973144582180062593244200961",
                "eventVersion": "1.0",
                "kinesis": {
                    "partitionKey":
                    "partitionKey-3",
                    "data":
                    "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=",
                    "kinesisSchemaVersion":
                    "1.0",
                    "sequenceNumber":
                    "49545115243490985018280067714973144582180062593244200961",
                },
                "invokeIdentityArn": "arn:aws:iam::EXAMPLE",
                "eventName": "aws:kinesis:record",
                "eventSourceARN": "arn:aws:kinesis:1",
                "eventSource": "aws:kinesis",
                "awsRegion": "us-east-1",
            }]
        }
        self.assertEqual("AWS KINESIS EVENT", lh.handler(event, None))

        # Test AWS SQS event
        event = {
            "Records": [{
                "messageId": "c80e8021-a70a-42c7-a470-796e1186f753",
                "receiptHandle":
                "AQEBJQ+/u6NsnT5t8Q/VbVxgdUl4TMKZ5FqhksRdIQvLBhwNvADoBxYSOVeCBXdnS9P+erlTtwEALHsnBXynkfPLH3BOUqmgzP25U8kl8eHzq6RAlzrSOfTO8ox9dcp6GLmW33YjO3zkq5VRYyQlJgLCiAZUpY2D4UQcE5D1Vm8RoKfbE+xtVaOctYeINjaQJ1u3mWx9T7tork3uAlOe1uyFjCWU5aPX/1OHhWCGi2EPPZj6vchNqDOJC/Y2k1gkivqCjz1CZl6FlZ7UVPOx3AMoszPuOYZ+Nuqpx2uCE2MHTtMHD8PVjlsWirt56oUr6JPp9aRGo6bitPIOmi4dX0FmuMKD6u/JnuZCp+AXtJVTmSHS8IXt/twsKU7A+fiMK01NtD5msNgVPoe9JbFtlGwvTQ==",
                "body": '{"foo":"bar"}',
                "attributes": {
                    "ApproximateReceiveCount": "3",
                    "SentTimestamp": "1529104986221",
                    "SenderId": "594035263019",
                    "ApproximateFirstReceiveTimestamp": "1529104986230",
                },
                "messageAttributes": {},
                "md5OfBody": "9bb58f26192e4ba00f01e2e7b136bbd8",
                "eventSource": "aws:sqs",
                "eventSourceARN": "arn:aws:sqs:1",
                "awsRegion": "us-east-1",
            }]
        }
        self.assertEqual("AWS SQS EVENT", lh.handler(event, None))

        # Test Authorizer event
        event = {
            "authorizationToken": "hubtoken1",
            "methodArn":
            "arn:aws:execute-api:us-west-2:1234:xxxxx/dev/GET/v1/endpoint/param",
            "type": "TOKEN",
        }
        self.assertEqual("AUTHORIZER_EVENT", lh.handler(event, None))

        # Ensure Zappa does return 401 if no function was defined.
        lh.settings.AUTHORIZER_FUNCTION = None
        with self.assertRaisesRegexp(Exception, "Unauthorized"):
            lh.handler(event, None)

        # Unhandled event
        event = {
            "Records": [{
                "eventID":
                "shardId-000000000000:49545115243490985018280067714973144582180062593244200961",
                "eventVersion": "1.0",
                "kinesis": {
                    "partitionKey":
                    "partitionKey-3",
                    "data":
                    "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=",
                    "kinesisSchemaVersion":
                    "1.0",
                    "sequenceNumber":
                    "49545115243490985018280067714973144582180062593244200961",
                },
                "eventSourceARN": "bad:arn:1",
            }]
        }
        self.assertIsNone(lh.handler(event, None))