def test_missing_description_error(self, aws_lambda_mock):
        aws_lambda_mock.get_function_configuration.return_value = {}

        with self.assertRaises(KeyError) as cm:
            aws_lambda_configurer.load_config(Context=MockContext('function-arn-name', 'function-version'))

        self.assertEqual('Description', cm.exception.message)
    def test_raise_json_error(self, aws_lambda_mock):
        aws_lambda_mock.get_function_configuration.return_value = {
            'Description': "i am not a json description"
        }

        with self.assertRaises(Exception) as cm:
            aws_lambda_configurer.load_config(Context=MockContext('function-arn-name', 'function-version'))

        self.assertEqual('Description of function must contain JSON, but was "i am not a json description"',
                         cm.exception.message)
    def test_raise_invalid_lookup(self, aws_lambda_mock):
        aws_lambda_mock.get_function_configuration.return_value = {
            'Description': json.dumps({
                '_lookup': {
                    'invalid_lookup_value': {}
            }})
        }
        with self.assertRaises(Exception) as cm:
            aws_lambda_configurer.load_config(Context=MockContext('function-arn-name', 'function-version'))

        self.assertIn('invalid_lookup_value', cm.exception.message)
    def test_raise_s3_lookup_missing_key(self, aws_lambda_mock):
        aws_lambda_mock.get_function_configuration.return_value = {
            'Description': json.dumps({
                '_lookup': {
                    's3': {
                        'bucket': 'bar'
                    }
            }})
        }
        with self.assertRaises(Exception) as cm:
            aws_lambda_configurer.load_config(Context=MockContext('function-arn-name', 'function-version'))

        self.assertIn("config needs field 'key'" , cm.exception.message)
    def test_lookup_s3(self, s3_mock, aws_lambda_mock):
        aws_lambda_mock.get_function_configuration.return_value = {
            'Description': json.dumps({
                "_lookup": {
                    "s3": {
                        "bucket": "mybucket",
                        "key": "my-key"
                    }
                },
                "abc": 123,
                "override": 1
            })
        }

        self.mock_s3_get(
            s3_mock,
            {
                "foo": "bar",
                "override": 2

            })

        config = aws_lambda_configurer.load_config(Context=MockContext('function-arn-name', 'function-version'))
        self.assertEquals(config, {
            "abc": 123,
            "foo": "bar",
            "override": 2
        })
        s3_mock.get_object.assert_called_once_with(Bucket='mybucket', Key='my-key')
Esempio n. 6
0
def get_config(context):
    config = load_config(Context=context)
    logging.info('Loaded config: {}'.format(config))
    logfile_type = config.get('type')
    stream_to_send = config.get('kinesisStream')
    origin = config.get('origin', 'rds')
    return logfile_type, stream_to_send, origin
    def test_get_config(self, aws_lambda_mock):
        aws_lambda_mock.get_function_configuration.return_value = {
            'Description': json.dumps({
                'endpoint': 'knuff.eu-west-1.es.amazonaws.com'
            })
        }

        config = aws_lambda_configurer.load_config(Context=MockContext('function-arn-name', 'function-version'))
        aws_lambda_mock.get_function_configuration.assert_called_once_with(FunctionName='function-arn-name',
                                                                           Qualifier='function-version')
        self.assertEquals(config, {
            'endpoint': 'knuff.eu-west-1.es.amazonaws.com'
        })
Esempio n. 8
0
def handler(event, context):
    properties = load_config(Context=context)
    sqs_queue = properties['sqs_queue']
    sender_email = properties['sender_email']
    recipients = properties['recipients']
    usofa_key = properties['usofa_key']
    usofa_bucket = properties['usofa_bucket']
    usofa_filter = properties.get('usofa_filter', {})
    region_name = properties['region_name']

    monocyte_alarm = MonocyteAlarm(sqs_queue=sqs_queue,
                                   sender_email=sender_email,
                                   recipients=recipients,
                                   usofa_key=usofa_key,
                                   usofa_bucket=usofa_bucket,
                                   usofa_filter=usofa_filter,
                                   region_name=region_name)
    monocyte_alarm()
def handler(event, context):
    properties = load_config(Context=context)
    sqs_queue = properties["sqs_queue"]
    sender_email = properties["sender_email"]
    recipients = properties["recipients"]
    usofa_key = properties["usofa_key"]
    usofa_bucket = properties["usofa_bucket"]
    usofa_filter = properties.get("usofa_filter", {})
    region_name = properties["region_name"]

    monocyte_alarm = MonocyteAlarm(
        sqs_queue=sqs_queue,
        sender_email=sender_email,
        recipients=recipients,
        usofa_key=usofa_key,
        usofa_bucket=usofa_bucket,
        usofa_filter=usofa_filter,
        region_name=region_name,
    )
    monocyte_alarm()
    def test_raise_missing_args_error(self):
        with self.assertRaises(Exception) as cm:
            aws_lambda_configurer.load_config()

        self.assertEqual("Keyword argument 'Context' missing", cm.exception.message)