def enable_lambda_integration(gql, nr_account_id, linked_account_name): """ Enables AWS Lambda for the specified New Relic Cloud integrations account. Returns True for success and False for failure. """ account = gql.get_linked_account_by_name(linked_account_name) if account is None: failure("Could not find Cloud integrations account " "[%s] in New Relic account [%d]." % (linked_account_name, nr_account_id)) return False is_lambda_enabled = gql.is_integration_enabled(account["id"], "lambda") if is_lambda_enabled: success("The AWS Lambda integration is already enabled in " "Cloud integrations account [%s] of New Relic account [%d]." % (linked_account_name, nr_account_id)) return True try: integration = gql.enable_integration(account["id"], "aws", "lambda") except Exception: failure( "Could not enable New Relic AWS Lambda integration. Make sure your New " "Relic account is a Pro plan and try this command again.") return False else: success("Integration [id=%s, name=%s] has been enabled in Cloud " "integrations account [%s] of New Relic account [%d]." % ( integration["id"], integration["name"], linked_account_name, nr_account_id, )) return True
def enable_lambda_integration(gql, input, linked_account_id): """ Enables AWS Lambda for the specified New Relic Cloud integrations account. Returns True for success and False for failure. """ assert isinstance(gql, NewRelicGQL) assert isinstance(input, IntegrationInstall) account = gql.get_linked_account_by_id(linked_account_id) if account is None: failure("Could not find Cloud integrations account " "[%d] in New Relic account [%d]." % (linked_account_id, input.nr_account_id)) return False metric_collection_mode = account["metricCollectionMode"] if metric_collection_mode == "PUSH": success( "Cloud integrations account [%s] is using CloudWatch Metric Streams" % (input.nr_account_id)) return True is_lambda_enabled = gql.is_integration_enabled(linked_account_id, "lambda") if is_lambda_enabled: success("The AWS Lambda integration is already enabled in " "Cloud integrations account [%s] of New Relic account [%d]." % (account["name"], input.nr_account_id)) return True try: integration = gql.enable_integration(linked_account_id, "aws", "lambda") except Exception: failure( "Could not enable New Relic AWS Lambda integration for Cloud integrations " "account [%s] in New Relic account [%d]. Please contact New Relic Support " "for assistance." % (account["name"], input.nr_account_id)) return False if integration: success("Integration [id=%s, name=%s] has been enabled in Cloud " "integrations account [%s] of New Relic account [%d]." % ( integration["id"], integration["name"], account["name"], input.nr_account_id, )) return True failure( "Something went wrong while enabling the New Relic AWS Lambda integration. " "Please contact New Relic support for further assistance.") return False
def enable_lambda_integration(gql, input): """ Enables AWS Lambda for the specified New Relic Cloud integrations account. Returns True for success and False for failure. """ assert isinstance(gql, NewRelicGQL) assert isinstance(input, IntegrationInstall) account = gql.get_linked_account_by_name(input.linked_account_name) if account is None: failure("Could not find Cloud integrations account " "[%s] in New Relic account [%d]." % (input.linked_account_name, input.nr_account_id)) return False is_lambda_enabled = gql.is_integration_enabled(account["id"], "lambda") if is_lambda_enabled: success("The AWS Lambda integration is already enabled in " "Cloud integrations account [%s] of New Relic account [%d]." % (input.linked_account_name, input.nr_account_id)) return True try: integration = gql.enable_integration(account["id"], "aws", "lambda") except Exception: failure( "Could not enable New Relic AWS Lambda integration. Make sure your New " "Relic account is a Pro plan and try this command again.") return False if integration: success("Integration [id=%s, name=%s] has been enabled in Cloud " "integrations account [%s] of New Relic account [%d]." % ( integration["id"], integration["name"], input.linked_account_name, input.nr_account_id, )) return True failure( "Something went wrong while enabling the New Relic AWS Lambda integration. " "Please contact New Relic support for further assistance.") return False