diff --git a/src/api.ts b/src/api.ts index 3becf337..b7bff08f 100644 --- a/src/api.ts +++ b/src/api.ts @@ -11,6 +11,8 @@ export const nerdgraphFetch = async ( const gqlUrl = region === "eu" ? "https://api.eu.newrelic.com/graphql" + : region === "staging" + ? "https://staging-api.newrelic.com/graphql" : "https://api.newrelic.com/graphql"; const agent = diff --git a/src/integration.ts b/src/integration.ts index 945c3bdb..4690d63c 100644 --- a/src/integration.ts +++ b/src/integration.ts @@ -30,9 +30,6 @@ export default class Integration { nrRegion, proxy } = this.config; - const { - linkedAccount = `New Relic Lambda Integration - ${accountId}` - } = this.config; const integrationData = await nerdgraphFetch( apiKey, @@ -55,7 +52,6 @@ export default class Integration { const match = linkedAccounts.filter(account => { return ( - account.name === linkedAccount && account.externalId === externalId && account.nrAccountId === parseInt(accountId, 10) ); @@ -66,7 +62,7 @@ export default class Integration { "No New Relic AWS Lambda integration found for this New Relic linked account and aws account." ); - if (enableIntegration) { + if (enableIntegration && enableIntegration !== "false") { this.enable(externalId); return; } @@ -251,6 +247,19 @@ export default class Integration { } } + private async requestRoleArn(RoleName: string) { + const params = { + RoleName + }; + const response = await this.awsProvider.request("IAM", "getRole", params); + + const { + Role: { Arn } + } = response; + + return Arn; + } + private async checkAwsIntegrationRole(externalId: string) { const { accountId } = this.config; if (!accountId) { @@ -261,31 +270,29 @@ export default class Integration { } try { - const params = { - RoleName: `NewRelicLambdaIntegrationRole_${accountId}` - }; - - const { - Role: { Arn } - } = await this.awsProvider.request("IAM", "getRole", params); - - return Arn; + return this.requestRoleArn(`NewRelicLambdaIntegrationRole_${accountId}`); } catch (err) { - this.serverless.cli.log( - "The required NewRelicLambdaIntegrationRole cannot be found; Creating Stack with NewRelicLambdaIntegrationRole." - ); - const stackId = await this.createCFStack(accountId); - waitForStatus( - { - awsMethod: "describeStacks", - callbackMethod: () => this.enable(externalId), - methodParams: { - StackName: stackId + // We're limited to one rolename and a 64-character regex, so allowing for streams means a second query + try { + return this.requestRoleArn(`NewRelicInfrastructure-Integrations`); + } catch (fallbackErr) { + this.serverless.cli.log( + `Neither NewRelicLambdaIntegrationRole_${accountId} nor NewRelicInfrastructure-Integrations can be found. + Creating Stack with NewRelicLambdaIntegrationRole.` + ); + const stackId = await this.createCFStack(accountId); + waitForStatus( + { + awsMethod: "describeStacks", + callbackMethod: () => this.enable(externalId), + methodParams: { + StackName: stackId + }, + statusPath: "Stacks[0].StackStatus" }, - statusPath: "Stacks[0].StackStatus" - }, - this - ); + this + ); + } } }