Пример #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(aws_profile, aws_region, aws_permissions_check, nr_account_id,
              force):
    """Uninstall New Relic AWS Lambda Integration"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_integration_uninstall_permissions(session)

    uninstall_integration = True

    if not force and nr_account_id:
        uninstall_integration = click.confirm(
            "This will uninstall the New Relic AWS Lambda integration role. "
            "Are you sure you want to proceed?")

    if uninstall_integration and nr_account_id:
        integrations.remove_integration_role(session, nr_account_id)

    if not force:
        click.confirm(
            "This will uninstall the New Relic AWS Lambda log ingestion function and "
            "role. Are you sure you want to proceed?",
            abort=True,
            default=False,
        )

    integrations.remove_log_ingestion_function(session)

    done("Uninstall Complete")
Пример #4
0
def update(**kwargs):
    """UpdateNew Relic AWS Lambda Integration"""
    input = IntegrationUpdate(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_integration_install_permissions(input)

    update_success = True

    click.echo("Updating newrelic-log-ingestion Lambda function in AWS account")
    res = integrations.update_log_ingestion(input)
    update_success = res and update_success

    if input.enable_license_key_secret:
        update_success = update_success and integrations.auto_install_license_key(input)
    else:
        integrations.remove_license_key(input)

    if update_success:
        done("Update Complete")
    else:
        failure("Update Incomplete. See messages above for details.", exit=True)
Пример #5
0
def update(
    aws_profile,
    aws_region,
    aws_permissions_check,
    enable_logs,
    memory_size,
    timeout,
    role_name,
):
    """UpdateNew Relic AWS Lambda Integration"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_integration_install_permissions(session)

    update_success = True

    click.echo(
        "Updating newrelic-log-ingestion Lambda function in AWS account")
    res = integrations.update_log_ingestion(session, None, enable_logs,
                                            memory_size, timeout, role_name)
    update_success = res and update_success

    if update_success:
        done("Update Complete")
    else:
        failure("Update Incomplete. See messages above for details.",
                exit=True)
Пример #6
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)
Пример #7
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)
Пример #8
0
def uninstall(aws_profile, aws_region, aws_permissions_check, function):
    """Uninstall New Relic AWS Lambda Log Subscription"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_subscription_uninstall_permissions(session)

    subscriptions.remove_log_subscription(session, function)
    done("Uninstall Complete")
Пример #9
0
def install(
    aws_profile,
    aws_region,
    aws_permissions_check,
    aws_role_policy,
    linked_account_name,
    nr_account_id,
    nr_api_key,
    nr_region,
):
    """Install New Relic AWS Lambda Integration"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_integration_install_permissions(session)

    click.echo("Validating New Relic credentials")
    gql_client = api.validate_gql_credentials(nr_account_id, nr_api_key,
                                              nr_region)

    click.echo("Retrieving integration license key")
    nr_license_key = api.retrieve_license_key(gql_client)

    click.echo("Checking for a pre-existing link between New Relic and AWS")
    integrations.validate_linked_account(session, gql_client,
                                         linked_account_name)

    click.echo(
        "Creating the AWS role for the New Relic AWS Lambda Integration")
    role = integrations.create_integration_role(session, aws_role_policy,
                                                nr_account_id)

    install_success = False
    if role:
        click.echo("Linking New Relic account to AWS account")
        api.create_integration_account(gql_client, nr_account_id,
                                       linked_account_name, role)

        click.echo(
            "Enabling Lambda integration on the link between New Relic and AWS"
        )
        install_success = api.enable_lambda_integration(
            gql_client, nr_account_id, linked_account_name)

    click.echo(
        "Creating newrelic-log-ingestion Lambda function in AWS account")
    install_success = install_success and integrations.install_log_ingestion(
        session, nr_license_key)

    if install_success:
        done("Install Complete")
    else:
        failure("Install Incomplete. See messages above for details.")
Пример #10
0
def uninstall(ctx, aws_profile, aws_region, aws_permissions_check, function):
    """Uninstall New Relic AWS Lambda Layer"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_lambda_uninstall_permissions(session)

    res = layers.uninstall(session, function)

    if ctx.obj["VERBOSE"]:
        click.echo(json.dumps(res, indent=2))

    done("Uninstall Complete")
Пример #11
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)
Пример #12
0
def uninstall(**kwargs):
    """Uninstall New Relic AWS Lambda Integration"""
    input = IntegrationUninstall(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_integration_uninstall_permissions(input)

    uninstall_integration = True

    if not input.force and input.nr_account_id:
        uninstall_integration = click.confirm(
            "This will uninstall the New Relic AWS Lambda integration role. "
            "Are you sure you want to proceed?"
        )

    if uninstall_integration and input.nr_account_id:
        integrations.remove_integration_role(input)

    if not input.force:
        click.confirm(
            "This will uninstall the New Relic AWS Lambda log ingestion function and "
            "role. Are you sure you want to proceed?",
            abort=True,
            default=False,
        )

    integrations.remove_log_ingestion_function(input)

    if not input.force:
        click.confirm(
            "This will uninstall the New Relic License Key managed secret, and IAM "
            "Policy. "
            "Are you sure you want to proceed?",
            abort=True,
            default=False,
        )
    integrations.remove_license_key(input)

    done("Uninstall Complete")
Пример #13
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)
Пример #14
0
def install(
    ctx,
    nr_account_id,
    aws_profile,
    aws_region,
    aws_permissions_check,
    function,
    layer_arn,
    upgrade,
):
    """Install New Relic AWS Lambda Layer"""
    session = boto3.Session(profile_name=aws_profile, region_name=aws_region)

    if aws_permissions_check:
        permissions.ensure_lambda_install_permissions(session)

    res = layers.install(session, function, layer_arn, nr_account_id, upgrade)

    if ctx.obj["VERBOSE"]:
        click.echo(json.dumps(res, indent=2))

    done("Install Complete")
Пример #15
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)
Пример #16
0
def install(ctx, **kwargs):
    """Install New Relic AWS Lambda Integration"""
    input = IntegrationInstall(session=None, verbose=ctx.obj["VERBOSE"], **kwargs)

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

    if not input.linked_account_name:
        input = input._replace(
            linked_account_name=(
                "New Relic Lambda Integration - %s"
                % integrations.get_aws_account_id(input.session)
            )
        )

    if input.aws_permissions_check:
        permissions.ensure_integration_install_permissions(input)

    click.echo("Validating New Relic credentials")
    gql_client = api.validate_gql_credentials(input)

    click.echo("Retrieving integration license key")
    nr_license_key = api.retrieve_license_key(gql_client)

    click.echo("Checking for a pre-existing link between New Relic and AWS")
    integrations.validate_linked_account(gql_client, input)

    install_success = True

    click.echo("Creating the AWS role for the New Relic AWS Lambda Integration")
    role = integrations.create_integration_role(input)
    install_success = install_success and role

    if role:
        click.echo("Linking New Relic account to AWS account")
        res = api.create_integration_account(gql_client, input, role)
        install_success = res and install_success

        click.echo("Enabling Lambda integration on the link between New Relic and AWS")
        res = api.enable_lambda_integration(gql_client, input)
        install_success = res and install_success

    if input.enable_license_key_secret:
        click.echo("Creating the managed secret for the New Relic License Key")
        res = integrations.install_license_key(input, nr_license_key)
        install_success = install_success and res

    if input.enable_cw_ingest:
        click.echo("Creating newrelic-log-ingestion Lambda function in AWS account")
        res = integrations.install_log_ingestion(input, nr_license_key)
        install_success = res and install_success

    if install_success:
        done("Install Complete")

        if input.verbose:
            click.echo(
                "\nNext steps: Add the New Relic layers to your Lambda functions with "
                "the below command.\n"
            )
            command = [
                "$",
                "newrelic-lambda",
                "layers",
                "install",
                "--function",
                "all",
                "--nr-account-id",
                input.nr_account_id,
            ]
            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))
    else:
        failure("Install Incomplete. See messages above for details.", exit=True)