Beispiel #1
0
def list(aws_profile, aws_region, aws_permissions_check, filter):
    """List AWS Lambda Functions"""
    _, rows = shutil.get_terminal_size((80, 50))
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_lambda_list_permissions(session)

    funcs = functions.list_functions(session, filter)

    def _format(funcs, header=False):
        table = []
        for func in funcs:
            table.append([
                func.get("FunctionName"),
                func.get("Runtime"),
                "Yes" if func.get("x-new-relic-enabled", False) else "No",
            ])
        return tabulate(table,
                        headers=["Function Name", "Runtime", "Installed"]
                        if header else []).rstrip()

    buffer = []
    for i, func in enumerate(funcs):
        buffer.append(func)
        if i > 0 and i % rows == 0:
            click.echo_via_pager(
                itertools.chain(iter(_format(buffer, header=True)),
                                _format(funcs)))
            buffer = []
            return

    click.echo(_format(buffer, header=True))
Beispiel #2
0
def test_list_functions(aws_credentials):
    session = boto3.Session(region_name="us-east-1")
    assert list(list_functions(session)) == []

    mock_session = MagicMock()
    mock_client = mock_session.client.return_value
    mock_pager = mock_client.get_paginator.return_value
    mock_pager.paginate.return_value = [{
        "Functions": [{
            "FunctionName": "foobar",
            "Layers": []
        }]
    }]

    assert list(list_functions(mock_session)) == [{
        "FunctionName": "foobar",
        "Layers": [],
        "x-new-relic-enabled": False
    }]