當前位置: 首頁>>代碼示例>>Python>>正文


Python PythonPackageArchive.create方法代碼示例

本文整理匯總了Python中c7n.mu.PythonPackageArchive.create方法的典型用法代碼示例。如果您正苦於以下問題:Python PythonPackageArchive.create方法的具體用法?Python PythonPackageArchive.create怎麽用?Python PythonPackageArchive.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在c7n.mu.PythonPackageArchive的用法示例。


在下文中一共展示了PythonPackageArchive.create方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_function

# 需要導入模塊: from c7n.mu import PythonPackageArchive [as 別名]
# 或者: from c7n.mu.PythonPackageArchive import create [as 別名]
def get_function(session_factory, options, groups):
    config = dict(
        name='cloud-maid-error-notify',
        handler='logsub.process_log_event',
        runtime='python2.7',
        memory_size=512,
        timeout=15,
        role=options.role,
        description='Maid Error Notify',
        events=[
            CloudWatchLogSubscription(
                session_factory, groups, options.pattern)])


    archive = PythonPackageArchive(
        # Directory to lambda file
        os.path.join(
            os.path.dirname(inspect.getabsfile(c7n)), 'logsub.py'),
        # Don't include virtualenv deps
        lib_filter=lambda x, y, z: ([], []))
    archive.create()
    archive.add_contents(
        'config.json', json.dumps({
            'topic': options.topic,
            'subject': options.subject
        }))
    archive.close()
    
    return LambdaFunction(config, archive)
開發者ID:MHarris021,項目名稱:cloud-custodian,代碼行數:31,代碼來源:logsetup.py

示例2: get_function

# 需要導入模塊: from c7n.mu import PythonPackageArchive [as 別名]
# 或者: from c7n.mu.PythonPackageArchive import create [as 別名]
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
    import inspect
    import os

    import c7n
    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(
        # Directory to lambda file
        os.path.join(
            os.path.dirname(inspect.getabsfile(c7n)), 'ufuncs', 'logsub.py'),
        # Don't include virtualenv deps
        lib_filter=lambda x, y, z: ([], []))
    archive.create()
    archive.add_contents(
        'config.json', json.dumps({
            'topic': sns_topic,
            'subject': subject
        }))
    archive.close()

    return LambdaFunction(config, archive)
開發者ID:tomzhang,項目名稱:cloud-custodian,代碼行數:44,代碼來源:logsub.py

示例3: test_lambda_cross_account

# 需要導入模塊: from c7n.mu import PythonPackageArchive [as 別名]
# 或者: from c7n.mu.PythonPackageArchive import create [as 別名]
    def test_lambda_cross_account(self):
        self.patch(
            CrossAccountAccessFilter, 'executor_factory', MainThreadExecutor)
        
        session_factory = self.replay_flight_data('test_cross_account_lambda')
        client = session_factory().client('lambda')
        name = 'c7n-cross-check'

        tmp_dir = tempfile.mkdtemp()
        self.addCleanup(os.rmdir, tmp_dir)
        archive = PythonPackageArchive(tmp_dir, tmp_dir)
        archive.create()
        archive.add_contents('handler.py', LAMBDA_SRC)
        archive.close()

        func = LambdaFunction({
            'runtime': 'python2.7',
            'name': name, 'description': '',
            'handler': 'handler.handler',
            'memory_size': 128,
            'timeout': 5,
            'role': self.role}, archive)
        manager = LambdaManager(session_factory)
        info = manager.publish(func)
        self.addCleanup(manager.remove, func)

        client.add_permission(
            FunctionName=name,
            StatementId='oops',
            Principal='*',
            Action='lambda:InvokeFunction')

        p = self.load_policy(
            {'name': 'lambda-cross',
             'resource': 'lambda',
             'filters': ['cross-account']},
            session_factory=session_factory)
        resources = p.run()
        self.assertEqual(len(resources), 1)
        self.assertEqual(resources[0]['FunctionName'], name)
開發者ID:tomzhang,項目名稱:cloud-custodian,代碼行數:42,代碼來源:test_iam.py

示例4: get_archive

# 需要導入模塊: from c7n.mu import PythonPackageArchive [as 別名]
# 或者: from c7n.mu.PythonPackageArchive import create [as 別名]
def get_archive(config):

    required = ['ldap', 'jinja2', 'markupsafe']
    remove = ['_yaml.so', 'c7n.egg-link']

    def lib_filter(root, dirs, files):
        for f in tuple(files):
            if f.endswith('.pyo'):
                files.remove(f)
        for r in remove:
            if r in files:
                files.remove(r)

        if os.path.basename(root) == 'site-packages':
            for n in tuple(dirs):
                if n not in required:
                    dirs.remove(n)
        return dirs, files

    archive = PythonPackageArchive(
        os.path.dirname(__file__),
        skip='*.pyc',
        lib_filter=lib_filter)

    archive.create()

    template_dir = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', 'msg-templates'))

    for t in os.listdir(template_dir):
        with open(os.path.join(template_dir, t)) as fh:
            archive.add_contents('msg-templates/%s' % t, fh.read())

    archive.add_contents('config.json', json.dumps(config))
    archive.add_contents('periodic.py', entry_source)

    archive.close()
    return archive
開發者ID:andrewalexander,項目名稱:cloud-custodian,代碼行數:40,代碼來源:deploy.py


注:本文中的c7n.mu.PythonPackageArchive.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。