Пример #1
0
def install(
    ctx,
    nr_account_id,
    aws_profile,
    aws_region,
    aws_permissions_check,
    functions,
    excludes,
    layer_arn,
    upgrade,
):
    """Install New Relic AWS Lambda Layers"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_lambda_install_permissions(session)

    functions = get_aliased_functions(session, functions, excludes)

    install_success = True

    for function in functions:
        res = layers.install(session, function, layer_arn, nr_account_id,
                             upgrade)
        install_success = res and install_success
        if res:
            success("Successfully installed layer on %s" % function)
            if ctx.obj["VERBOSE"]:
                click.echo(json.dumps(res, indent=2))

    if install_success:
        done("Install Complete")
    else:
        failure("Install Incomplete. See messages above for details.",
                exit=True)
Пример #2
0
def install(
    aws_profile, aws_region, aws_permissions_check, functions, excludes, filter_pattern
):
    """Install New Relic AWS Lambda Log Subscriptions"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_subscription_install_permissions(session)

    functions = get_aliased_functions(session, functions, excludes)

    install_success = True

    for function in functions:
        result = subscriptions.create_log_subscription(
            session, function, filter_pattern
        )
        install_success = result and install_success
        if result:
            success("Successfully installed log subscription on %s" % function)

    if install_success:
        done("Install Complete")
    else:
        failure("Install Incomplete. See messages above for details.", exit=True)
Пример #3
0
def uninstall(ctx, **kwargs):
    """Uninstall New Relic AWS Lambda Layers"""
    input = LayerUninstall(session=None, verbose=ctx.obj["VERBOSE"], **kwargs)

    input = input._replace(session=boto3.Session(
        profile_name=input.aws_profile, region_name=input.aws_region))

    if input.aws_permissions_check:
        permissions.ensure_layer_uninstall_permissions(input)

    functions = get_aliased_functions(input)

    with ThreadPoolExecutor() as executor:
        futures = [
            executor.submit(layers.uninstall, input, function)
            for function in functions
        ]
        uninstall_success = all(future.result()
                                for future in as_completed(futures))

    if uninstall_success:
        done("Uninstall Complete")
    else:
        failure("Uninstall Incomplete. See messages above for details.",
                exit=True)
Пример #4
0
def install(**kwargs):
    """Install New Relic AWS Lambda Log Subscriptions"""
    input = SubscriptionInstall(session=None, **kwargs)

    input = input._replace(session=boto3.Session(
        profile_name=input.aws_profile, region_name=input.aws_region))

    if input.aws_permissions_check:
        permissions.ensure_subscription_install_permissions(input)

    functions = get_aliased_functions(input)

    with ThreadPoolExecutor() as executor:
        futures = [
            executor.submit(subscriptions.create_log_subscription, input,
                            function) for function in functions
        ]
        install_success = all(future.result()
                              for future in as_completed(futures))

    if install_success:
        done("Install Complete")
    else:
        failure("Install Incomplete. See messages above for details.",
                exit=True)
Пример #5
0
def test_get_aliased_functions(mock_list_functions, aws_credentials):
    """
    Asserts that get_aliased_functions adds functions matching one of the alias filters
    """
    session = boto3.Session(region_name="us-east-1")

    assert get_aliased_functions(session, [], []) == []
    assert get_aliased_functions(session, ["foo"], []) == ["foo"]
    assert get_aliased_functions(session, ["foo", "bar"], ["bar"]) == ["foo"]
    assert get_aliased_functions(session, ["foo", "bar", "baz"], ["bar"]) == [
        "foo",
        "baz",
    ]

    mock_list_functions.return_value = [{"FunctionName": "aliased-func"}]
    assert get_aliased_functions(session, ["foo", "bar", "all"], []) == [
        "foo",
        "bar",
        "aliased-func",
    ]

    mock_list_functions.return_value = [
        {"FunctionName": "aliased-func"},
        {"FunctionName": "ignored-func"},
        {"FunctionName": "newrelic-log-ingestion"},
    ]
    assert get_aliased_functions(session, ["foo", "bar", "all"], ["ignored-func"]) == [
        "foo",
        "bar",
        "aliased-func",
    ]
Пример #6
0
def install(ctx, **kwargs):
    """Install New Relic AWS Lambda Layers"""
    input = LayerInstall(session=None, verbose=ctx.obj["VERBOSE"], **kwargs)

    input = input._replace(session=boto3.Session(
        profile_name=input.aws_profile, region_name=input.aws_region))

    if input.aws_permissions_check:
        permissions.ensure_layer_install_permissions(input)

    functions = get_aliased_functions(input)

    with ThreadPoolExecutor() as executor:
        futures = [
            executor.submit(layers.install, input, function)
            for function in functions
        ]
        install_success = all(future.result()
                              for future in as_completed(futures))

    if install_success:
        done("Install Complete")
        if ctx.obj["VERBOSE"]:
            click.echo(
                "\nNext step. Configure the CloudWatch subscription filter for your "
                "Lambda functions with the below command:\n")
            command = [
                "$",
                "newrelic-lambda",
                "subscriptions",
                "install",
                "--function",
                "all",
            ]
            if input.aws_profile:
                command.append("--aws-profile %s" % input.aws_profile)
            if input.aws_region:
                command.append("--aws-region %s" % input.aws_region)
            click.echo(" ".join(command))
            click.echo(
                "\nIf you used `--enable-logs` for the `newrelic-lambda integrations "
                "install` command earlier, run this command instead:\n")
            command.append('--filter-pattern ""')
            click.echo(" ".join(command))
    else:
        failure("Install Incomplete. See messages above for details.",
                exit=True)
Пример #7
0
def install(
    ctx,
    nr_account_id,
    aws_profile,
    aws_region,
    aws_permissions_check,
    functions,
    excludes,
    layer_arn,
    upgrade,
):
    """Install New Relic AWS Lambda Layers"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_lambda_install_permissions(session)

    functions = get_aliased_functions(session, functions, excludes)

    with ThreadPoolExecutor() as executor:
        futures = [
            executor.submit(
                layers.install,
                session,
                function,
                layer_arn,
                nr_account_id,
                upgrade,
                ctx.obj["VERBOSE"],
            ) for function in functions
        ]
        install_success = all(future.result()
                              for future in as_completed(futures))

    if install_success:
        done("Install Complete")
    else:
        failure("Install Incomplete. See messages above for details.",
                exit=True)
Пример #8
0
def uninstall(aws_profile, aws_region, aws_permissions_check, functions,
              excludes):
    """Uninstall New Relic AWS Lambda Log Subscriptions"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_subscription_uninstall_permissions(session)

    functions = get_aliased_functions(session, functions, excludes)

    with ThreadPoolExecutor() as executor:
        futures = [
            executor.submit(subscriptions.remove_log_subscription, session,
                            function) for function in functions
        ]
        uninstall_success = all(future.result()
                                for future in as_completed(futures))

    if uninstall_success:
        done("Uninstall Complete")
    else:
        failure("Uninstall Incomplete. See messages above for details.",
                exit=True)