def create_integration_account(gql, nr_account_id, linked_account_name, role): """ Creates a New Relic Cloud integration account for the specified AWS IAM role. """ role_arn = role["Role"]["Arn"] account = gql.get_linked_account_by_name(linked_account_name) if account: success( "Cloud integrations account [%s] already exists " "in New Relic account [%d]." % (account["name"], nr_account_id) ) return account account = account = gql.link_account(role_arn, linked_account_name) if account: success( "Cloud integrations account [%s] was created in New Relic account [%s] " "with role [%s]." % (linked_account_name, nr_account_id, role_arn) ) return account failure( "Could not create Cloud integrations account [%s] in New Relic account [%s] " "with role [%s]. This may be due to a previously installed integration. " "Please contact New Relic support for assistance." % (linked_account_name, nr_account_id, role_arn) )
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 create_integration_account(gql, nr_account_id, linked_account_name, role): """ Creates a New Relic Cloud integration account for the specified AWS IAM role. """ role_arn = role["Role"]["Arn"] account = gql.get_linked_account_by_name(linked_account_name) if account is None: account = gql.link_account(role_arn, linked_account_name) success( "Cloud integrations account [%s] was created in New Relic account [%s]" "with role [%s]." % (linked_account_name, nr_account_id, role_arn)) else: success("Cloud integrations account [%s] already exists " "in New Relic account [%d]." % (account["name"], nr_account_id)) return account
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