コード例 #1
0
def run(function):
    if not function:
        function = metadata.get('function')
    result = lmbda.invoke(FunctionName=function, LogType='Tail')
    log = b64decode(result['LogResult']).rstrip().split("\n")
    for line in log:
        say(line)
    print result['Payload'].read()
コード例 #2
0
def publish(description, timeout, memory, role, zip_file_only, zip_file_path):
    runtime = metadata.get('runtime')
    function = metadata.get('function')

    if description:
        metadata.update(description=description)
    else:
        try:
            description = metadata.get('description')
        except KeyError:
            raise ClickException(
                'Please provide a description with "--description"')

    if timeout:
        metadata.update(timeout=timeout)
    else:
        timeout = metadata.get('timeout')

    if memory:
        metadata.update(memory=memory)
    else:
        memory = metadata.get('memory')

    if role:
        metadata.update(role=role)
    else:
        role = metadata.get('role')

    zip_data = open(create_zip(zip_file_path)).read()

    if zip_file_only:
        return

    if function in get_published_function_names():
        # Push the latest code to the existing function in Lambda.
        update_code_response = lmbda.update_function_code(
            FunctionName=function, ZipFile=zip_data, Publish=True)

        # Update any settings for the function too.
        final_response = lmbda.update_function_configuration(
            FunctionName=function,
            Description=description,
            Role=get_role_arn(role),
            Timeout=timeout,
            MemorySize=memory)
        say('%s updated in Lambda' % function)
    else:  # we need to explictly create the function in AWS.
        final_response = lmbda.create_function(FunctionName=function,
                                               Description=description,
                                               Runtime=runtime,
                                               Role=get_role_arn(role),
                                               Handler='%s.handler' % function,
                                               Code={'ZipFile': zip_data},
                                               Timeout=timeout,
                                               MemorySize=memory)
        say('%s created in Lambda' % function)
    print json.dumps(final_response, sort_keys=True, indent=2)
コード例 #3
0
def run(function):
    lmbda = boto3.client('lambda',
                         region_name=get_region(),
                         config=Config(retries={'max_attempts': 1},
                                       read_timeout=310))
    if not function:
        function = metadata.get('function')
    result = lmbda.invoke(FunctionName=function, LogType='Tail')
    log = b64decode(result['LogResult']).rstrip().split("\n")
    for line in log:
        say(line)
    print result['Payload'].read()
コード例 #4
0
def build():
    runtime = metadata.get('runtime')
    language = get_language_name_for_runtime(runtime)
    if language == 'python':
        # Use virtualenv and pip
        if not os.path.isfile('venv'):
            create_virtualenv('.')
        print run_in_virtualenv('pip install -r requirements.txt')
    else:
        # Fall back to a Makefile.
        try:
            make_log = check_output(['make'], stderr=STDOUT)
            for line in make_log.rstrip().split("\n"):
                say(line)
        except CalledProcessError as e:
            for line in e.output.rstrip().split("\n"):
                say(line)
            raise ClickException('make failure')
コード例 #5
0
def create(function, runtime):
    runtime = get_sane_runtime(runtime)

    ext = get_file_extension_for_runtime(runtime)
    func_dir = function
    func_file = os.path.join(func_dir, '%s.%s' % (function, ext))

    for path in (func_dir, func_file):
        if os.path.exists(path):
            raise ClickException('Path "%s" already exists.' % path)

    os.mkdir(func_dir)

    template_name = get_language_name_for_runtime(runtime)
    render_template(template_name,
                    function,
                    output_filename="%s.%s" % (function, ext))
    if get_language_name_for_runtime(runtime) == 'python':
        create_virtualenv(function)
        render_template('requirements',
                        function,
                        output_filename='requirements.txt')
        render_template('gitignore-python',
                        function,
                        output_filename='.gitignore')
    else:
        render_template('makefile', function, output_filename='Makefile')
        render_template('gitignore', function, output_filename='.gitignore')

    our_metadata = {
        'function': function,
        'runtime': runtime,
        'language': get_language_name_for_runtime(runtime),
        'timeout': metadata.get('timeout')
    }
    metadata.write(subdirectory=function, **our_metadata)

    say('%s created as %s' % (function, func_file))
コード例 #6
0
def unpublish(function):
    if not function:
        function = metadata.get('function')
    lmbda.delete_function(FunctionName=function)
    say('%s unpublished' % (function))