Пример #1
0
def get_function(session_factory, name, role, sns_topic, log_groups,
                 subject="Lambda Error", pattern="Traceback"):
    """Lambda function provisioning.

    Self contained within the component, to allow for easier reuse.
    """

    # Lazy import to avoid runtime dependency
    from c7n.mu import (
        LambdaFunction, PythonPackageArchive, CloudWatchLogSubscription)

    config = dict(
        name=name,
        handler='logsub.process_log_event',
        runtime='python2.7',
        memory_size=512,
        timeout=15,
        role=role,
        description='Custodian Ops Error Notify',
        events=[
            CloudWatchLogSubscription(
                session_factory, log_groups, pattern)])

    archive = PythonPackageArchive()
    archive.add_py_file(__file__)
    archive.add_contents(
        'config.json', json.dumps({
            'topic': sns_topic,
            'subject': subject
        }))
    archive.close()

    return LambdaFunction(config, archive)
Пример #2
0
def get_function(session_factory, name, role, sns_topic, log_groups,
                 subject="Lambda Error", pattern="Traceback"):
    """Lambda function provisioning.

    Self contained within the component, to allow for easier reuse.
    """

    # Lazy import to avoid runtime dependency
    from c7n.mu import (
        LambdaFunction, PythonPackageArchive, CloudWatchLogSubscription)

    config = dict(
        name=name,
        handler='logsub.process_log_event',
        runtime='python2.7',
        memory_size=512,
        timeout=15,
        role=role,
        description='Custodian Ops Error Notify',
        events=[
            CloudWatchLogSubscription(
                session_factory, log_groups, pattern)])

    archive = PythonPackageArchive()
    archive.add_py_file(__file__)
    archive.add_contents(
        'config.json', json.dumps({
            'topic': sns_topic,
            'subject': subject
        }))
    archive.close()

    return LambdaFunction(config, archive)
Пример #3
0
def get_function(session_factory, name, role, events):
    from c7n.mu import (LambdaFunction, PythonPackageArchive)

    config = dict(name=name,
                  handler='helloworld.main',
                  runtime='python2.7',
                  memory_size=512,
                  timeout=15,
                  role=role,
                  description='Hello World',
                  events=events)

    archive = PythonPackageArchive()
    archive.add_py_file(__file__)
    archive.close()

    return LambdaFunction(config, archive)
Пример #4
0
def get_function(session_factory, name, role, events):
    from c7n.mu import (LambdaFunction, PythonPackageArchive)

    config = dict(
        name=name,
        handler='helloworld.main',
        runtime='python2.7',
        memory_size=512,
        timeout=15,
        role=role,
        description='Hello World',
        events=events)

    archive = PythonPackageArchive()
    archive.add_py_file(__file__)
    archive.close()

    return LambdaFunction(config, archive)
Пример #5
0
 def test_reverts_to_py_if_available(self):
     archive = PythonPackageArchive()
     py = self.py_with_pyc('foo.py')
     archive.add_py_file(py+'c')
     archive.close()
     self.assertEqual(archive.get_filenames(), ['foo.py'])
Пример #6
0
 def test_can_add_py_file(self):
     archive = PythonPackageArchive()
     archive.add_py_file(self.py_with_pyc('foo.py'))
     archive.close()
     self.assertEqual(archive.get_filenames(), ['foo.py'])
Пример #7
0
 def test_reverts_to_py_if_available(self):
     archive = PythonPackageArchive()
     py = self.py_with_pyc('foo.py')
     archive.add_py_file(py+'c')
     archive.close()
     self.assertEqual(archive.get_filenames(), ['foo.py'])
Пример #8
0
 def test_can_add_py_file(self):
     archive = PythonPackageArchive()
     archive.add_py_file(self.py_with_pyc('foo.py'))
     archive.close()
     self.assertEqual(archive.get_filenames(), ['foo.py'])