diff --git a/package-lock.json b/package-lock.json index 591f2f0..d402e62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "serverless-newrelic-lambda-layers", - "version": "4.3.0", + "version": "5.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "serverless-newrelic-lambda-layers", - "version": "4.3.0", + "version": "5.0.1", "license": "Apache-2.0", "devDependencies": { "@types/fs-extra": "^9.0.13", diff --git a/package.json b/package.json index 4a72930..d59a0df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-newrelic-lambda-layers", - "version": "5.0.0", + "version": "5.0.1", "description": "Serverless plugin for NewRelic APM AWS Lambda layers.", "main": "dist/index.js", "files": [ diff --git a/src/index.ts b/src/index.ts index 54f0034..261faee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,14 +5,6 @@ import * as semver from "semver"; import * as Serverless from "serverless"; import { fetchLicenseKey, nerdgraphFetch } from "./api"; import Integration from "./integration"; -import { waitForStatus } from "./utils"; - -const DEFAULT_FILTER_PATTERNS = [ - "REPORT", - "NR_LAMBDA_MONITORING", - "Task timed out", - "RequestId", -]; const enum JavaHandler { handleRequest = "handleRequest", @@ -176,6 +168,14 @@ https://blog.newrelic.com/product-news/aws-lambda-extensions-integrations/ return new Integration(this).check(); } + public addLogSubscriptions() { + return new Integration(this).addLogSubscriptions(); + } + + public removeLogSubscriptions() { + return new Integration(this).removeLogSubscriptions(); + } + public async checkForSecretPolicy() { return new Integration(this).checkForManagedSecretPolicy(); } @@ -420,69 +420,6 @@ or make sure that you already have Serverless 3.x installed in your project. // any cleanup can happen here. Previously used for Node 8. } - public async addLogSubscriptions() { - if (this.autoSubscriptionDisabled) { - this.log.notice("Skipping adding log subscription. Explicitly disabled"); - return; - } - - const funcs = this.functions; - let { cloudWatchFilter = [...DEFAULT_FILTER_PATTERNS] } = this.config; - - let cloudWatchFilterString = ""; - if ( - typeof cloudWatchFilter === "object" && - cloudWatchFilter.indexOf("*") === -1 - ) { - cloudWatchFilter = cloudWatchFilter.map((el) => `?\"${el}\"`); - cloudWatchFilterString = cloudWatchFilter.join(" "); - } else if (cloudWatchFilter.indexOf("*") === -1) { - cloudWatchFilterString = String(cloudWatchFilter); - } - - this.log.notice(`log filter: ${cloudWatchFilterString}`); - - const promises = []; - - for (const funcName of Object.keys(funcs)) { - if (this.shouldSkipFunction(funcName)) { - return; - } - - this.log.notice(`Configuring New Relic log subscription for ${funcName}`); - - const funcDef = funcs[funcName]; - promises.push( - this.ensureLogSubscription(funcDef.name, cloudWatchFilterString) - ); - } - - await Promise.all(promises); - - if (this.extFellBackToCW) { - this.log.notice(this.extFallbackMessage); - } - } - - public async removeLogSubscriptions() { - if (this.autoSubscriptionDisabled) { - this.log.notice( - "Skipping removing log subscription. Explicitly disabled" - ); - return; - } - const funcs = this.functions; - const promises = []; - - for (const funcName of Object.keys(funcs)) { - const { name } = funcs[funcName]; - this.log.notice(`Removing New Relic log subscription for ${funcName}`); - promises.push(this.removeSubscriptionFilter(name)); - } - - await Promise.all(promises); - } - private async addLayer( funcName: string, funcDef: any, @@ -776,175 +713,6 @@ or make sure that you already have Serverless 3.x installed in your project. return pkg; } - private async ensureLogSubscription( - funcName: string, - cloudWatchFilterString: string - ) { - try { - await this.awsProvider.request("Lambda", "getFunction", { - FunctionName: funcName, - }); - } catch (err) { - if (err.providerError) { - this.log.error(err.providerError.message); - } - return; - } - - let destinationArn; - - const { logIngestionFunctionName = "newrelic-log-ingestion", apiKey } = - this.config; - - try { - destinationArn = await this.getDestinationArn(logIngestionFunctionName); - } catch (err) { - this.log.error( - `Could not find a \`${logIngestionFunctionName}\` function installed.` - ); - this.log.warning( - "Details about setup requirements are available here: https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/get-started/enable-new-relic-monitoring-aws-lambda#enable-process" - ); - if (err.providerError) { - this.log.error(err.providerError.message); - } - if (!apiKey) { - this.log.error( - "Unable to create newrelic-log-ingestion because New Relic API key not configured." - ); - return; - } - - this.log.notice( - `creating required newrelic-log-ingestion function in region ${this.region}` - ); - await this.addLogIngestionFunction(); - return; - } - - let subscriptionFilters; - - try { - subscriptionFilters = await this.describeSubscriptionFilters(funcName); - } catch (err) { - if (err.providerError) { - this.log.error(err.providerError.message); - } - return; - } - - const competingFilters = subscriptionFilters.filter( - (filter) => filter.filterName !== "NewRelicLogStreaming" - ); - - if (competingFilters.length) { - this.log.warning( - "WARNING: Found a log subscription filter that was not installed by New Relic. This may prevent the New Relic log subscription filter from being installed. If you know you don't need this log subscription filter, you should first remove it and rerun this command. If your organization requires this log subscription filter, please contact New Relic at serverless@newrelic.com for assistance with getting the AWS log subscription filter limit increased." - ); - } - - const existingFilters = subscriptionFilters.filter( - (filter) => filter.filterName === "NewRelicLogStreaming" - ); - - if (existingFilters.length) { - this.log.notice( - `Found log subscription for ${funcName}, verifying configuration` - ); - - await Promise.all( - existingFilters - .filter((filter) => filter.filterPattern !== cloudWatchFilterString) - .map(async (filter) => this.removeSubscriptionFilter(funcName)) - .map(async (filter) => - this.addSubscriptionFilter( - funcName, - destinationArn, - cloudWatchFilterString - ) - ) - ); - } else { - this.log.notice(`Adding New Relic log subscription to ${funcName}`); - - await this.addSubscriptionFilter( - funcName, - destinationArn, - cloudWatchFilterString - ); - } - } - - private async getDestinationArn(logIngestionFunctionName: string) { - try { - return this.awsProvider - .request("Lambda", "getFunction", { - FunctionName: logIngestionFunctionName, - }) - .then((res) => res.Configuration.FunctionArn); - } catch (e) { - this.log.error(`Error getting ingestion function destination ARN.`); - this.log.error(e); - } - } - - private async addLogIngestionFunction() { - const templateUrl = await this.getSarTemplate(); - if (!templateUrl) { - this.log.error( - "Unable to create newRelic-log-ingestion without sar template." - ); - return; - } - - try { - const mode = "CREATE"; - const stackName = "NewRelicLogIngestion"; - const changeSetName = `${stackName}-${mode}-${Date.now()}`; - const parameters = await this.formatFunctionVariables(); - - const params = { - Capabilities: ["CAPABILITY_IAM"], - ChangeSetName: changeSetName, - ChangeSetType: mode, - Parameters: parameters, - StackName: stackName, - TemplateURL: templateUrl, - }; - - let cfResponse; - try { - cfResponse = await this.awsProvider.request( - "CloudFormation", - "createChangeSet", - params - ); - } catch (e) { - this.log.error(`Unable to get stack information.`); - this.log.error(e); - } - const { Id, StackId } = cfResponse; - - this.log.notice( - "Waiting for change set creation to complete, this may take a minute..." - ); - - await waitForStatus( - { - awsMethod: "describeChangeSet", - callbackMethod: () => this.executeChangeSet(Id, StackId), - methodParams: { ChangeSetName: Id }, - statusPath: "Status", - }, - this - ); - } catch (err) { - this.log.warning( - "Unable to create newrelic-log-ingestion function. Please verify that required environment variables have been set." - ); - } - } - private async retrieveLicenseKey() { const { apiKey, accountId, nrRegion, proxy } = this.config; const userData = await nerdgraphFetch( @@ -957,110 +725,6 @@ or make sure that you already have Serverless 3.x installed in your project. this.licenseKey = _.get(userData, "data.actor.account.licenseKey", null); return this.licenseKey; } - - private async formatFunctionVariables() { - const { logEnabled } = this.config; - const licenseKey = this.licenseKey - ? this.licenseKey - : await this.retrieveLicenseKey(); - const loggingVar = logEnabled ? "True" : "False"; - - return [ - { - ParameterKey: "NRLoggingEnabled", - ParameterValue: `${loggingVar}`, - }, - { - ParameterKey: "NRLicenseKey", - ParameterValue: `${licenseKey}`, - }, - ]; - } - - private async getSarTemplate() { - try { - const data = await this.awsProvider.request( - "ServerlessApplicationRepository", - "createCloudFormationTemplate", - { - ApplicationId: - "arn:aws:serverlessrepo:us-east-1:463657938898:applications/NewRelic-log-ingestion", - } - ); - - const { TemplateUrl } = data; - return TemplateUrl; - } catch (err) { - this.log.error( - `Something went wrong while fetching the sar template: ${err}` - ); - } - } - - private async executeChangeSet(changeSetName: string, stackId: string) { - try { - await this.awsProvider.request("CloudFormation", "executeChangeSet", { - ChangeSetName: changeSetName, - }); - this.log.notice( - "Waiting for newrelic-log-ingestion install to complete, this may take a minute..." - ); - - await waitForStatus( - { - awsMethod: "describeStacks", - callbackMethod: () => this.addLogSubscriptions(), - methodParams: { StackName: stackId }, - statusPath: "Stacks[0].StackStatus", - }, - this - ); - } catch (changeSetErr) { - this.log.error( - `Something went wrong while executing the change set: ${changeSetErr}` - ); - } - } - - private async describeSubscriptionFilters(funcName: string) { - return this.awsProvider - .request("CloudWatchLogs", "describeSubscriptionFilters", { - logGroupName: `/aws/lambda/${funcName}`, - }) - .then((res) => res.subscriptionFilters); - } - - private async addSubscriptionFilter( - funcName: string, - destinationArn: string, - cloudWatchFilterString: string - ) { - return this.awsProvider - .request("CloudWatchLogs", "putSubscriptionFilter", { - destinationArn, - filterName: "NewRelicLogStreaming", - filterPattern: cloudWatchFilterString, - logGroupName: `/aws/lambda/${funcName}`, - }) - .catch((err) => { - if (err.providerError) { - this.log.error(err.providerError.message); - } - }); - } - - private removeSubscriptionFilter(funcName: string) { - return this.awsProvider - .request("CloudWatchLogs", "DeleteSubscriptionFilter", { - filterName: "NewRelicLogStreaming", - logGroupName: `/aws/lambda/${funcName}`, - }) - .catch((err) => { - if (err.providerError) { - this.log.error(err.providerError.message); - } - }); - } } module.exports = NewRelicLambdaLayerPlugin; diff --git a/src/integration.ts b/src/integration.ts index 8570704..4b6b079 100644 --- a/src/integration.ts +++ b/src/integration.ts @@ -7,13 +7,26 @@ import { } from "./api"; import { fetchPolicy, waitForStatus } from "./utils"; +const DEFAULT_FILTER_PATTERNS = [ + "REPORT", + "NR_LAMBDA_MONITORING", + "Task timed out", + "RequestId", +]; + export default class Integration { public config: any; public awsProvider: any; public serverless: any; public log: any; public region: string; + public functions: any; + public autoSubscriptionDisabled: boolean; + public shouldSkipFunction: any; + public extFellBackToCW: boolean; + public extFallbackMessage: string; private licenseKey: string; + private retrieveLicenseKey: any; constructor({ config, @@ -22,6 +35,12 @@ export default class Integration { region, licenseKey, log, + functions, + autoSubscriptionDisabled, + shouldSkipFunction, + extFellBackToCW, + extFallbackMessage, + retrieveLicenseKey, }: any) { this.config = config; this.log = log; @@ -29,6 +48,13 @@ export default class Integration { this.serverless = serverless; this.region = region; this.licenseKey = licenseKey; + this.region = region; + this.functions = functions; + this.autoSubscriptionDisabled = autoSubscriptionDisabled; + this.shouldSkipFunction = shouldSkipFunction; + this.extFellBackToCW = extFellBackToCW; + this.extFallbackMessage = extFallbackMessage; + this.retrieveLicenseKey = retrieveLicenseKey; } public async check() { @@ -368,4 +394,361 @@ export default class Integration { ); } } + + public async addLogSubscriptions() { + if (this.autoSubscriptionDisabled) { + this.log.notice("Skipping adding log subscription. Explicitly disabled"); + return; + } + + const funcs = this.functions; + let { cloudWatchFilter = [...DEFAULT_FILTER_PATTERNS] } = this.config; + + let cloudWatchFilterString = ""; + if ( + typeof cloudWatchFilter === "object" && + cloudWatchFilter.indexOf("*") === -1 + ) { + cloudWatchFilter = cloudWatchFilter.map((el) => `?\"${el}\"`); + cloudWatchFilterString = cloudWatchFilter.join(" "); + } else if (cloudWatchFilter.indexOf("*") === -1) { + cloudWatchFilterString = String(cloudWatchFilter); + } + + this.log.notice(`log filter: ${cloudWatchFilterString}`); + + const promises = []; + + for (const funcName of Object.keys(funcs)) { + if (this.shouldSkipFunction(funcName)) { + return; + } + + this.log.notice(`Configuring New Relic log subscription for ${funcName}`); + + const funcDef = funcs[funcName]; + promises.push( + this.ensureLogSubscription(funcDef.name, cloudWatchFilterString) + ); + } + + await Promise.all(promises); + + if (this.extFellBackToCW) { + this.log.notice(this.extFallbackMessage); + } + } + + public async removeLogSubscriptions() { + if (this.autoSubscriptionDisabled) { + this.log.notice( + "Skipping removing log subscription. Explicitly disabled" + ); + return; + } + const funcs = this.functions; + const promises = []; + + for (const funcName of Object.keys(funcs)) { + const { name } = funcs[funcName]; + this.log.notice(`Removing New Relic log subscription for ${funcName}`); + promises.push(this.removeSubscriptionFilter(name)); + } + + await Promise.all(promises); + } + + private async paginatedListFunctions(params, ingestionFnFilter) { + const results = await this.awsProvider.request( + "Lambda", + "listFunctions", + params + ); + + const existingIngestionFnResults = + results?.Functions?.filter(ingestionFnFilter); + if ( + results.NextMarker && + (!existingIngestionFnResults || existingIngestionFnResults.length === 0) + ) { + params.Marker = results.NextMarker; + return this.paginatedListFunctions(params, ingestionFnFilter); + } + return existingIngestionFnResults; + } + + public async getDestinationArn(logIngestionFunctionName: string) { + const ingestionFnFilter = (fnData) => + fnData.FunctionName.match(logIngestionFunctionName); + try { + const result = await this.paginatedListFunctions( + { MaxItems: 50 }, + ingestionFnFilter + ); + return result[0]?.FunctionArn; + } catch (e) { + this.log.error(`Error getting ingestion function destination ARN.`); + this.log.error(e); + } + } + + private async describeSubscriptionFilters(funcName: string) { + return this.awsProvider + .request("CloudWatchLogs", "describeSubscriptionFilters", { + logGroupName: `/aws/lambda/${funcName}`, + }) + .then((res) => res.subscriptionFilters); + } + + private async addSubscriptionFilter( + funcName: string, + destinationArn: string, + cloudWatchFilterString: string + ) { + return this.awsProvider + .request("CloudWatchLogs", "putSubscriptionFilter", { + destinationArn, + filterName: "NewRelicLogStreaming", + filterPattern: cloudWatchFilterString, + logGroupName: `/aws/lambda/${funcName}`, + }) + .catch((err) => { + if (err.providerError) { + this.log.error(err.providerError.message); + } + }); + } + + private removeSubscriptionFilter(funcName: string) { + return this.awsProvider + .request("CloudWatchLogs", "DeleteSubscriptionFilter", { + filterName: "NewRelicLogStreaming", + logGroupName: `/aws/lambda/${funcName}`, + }) + .catch((err) => { + if (err.providerError) { + this.log.error(err.providerError.message); + } + }); + } + + private async ensureLogSubscription( + funcName: string, + cloudWatchFilterString: string + ) { + try { + await this.awsProvider.request("Lambda", "getFunction", { + FunctionName: funcName, + }); + } catch (err) { + if (err.providerError) { + this.log.error(err.providerError.message); + } + return; + } + + let destinationArn; + + const { logIngestionFunctionName = "newrelic-log-ingestion", apiKey } = + this.config; + + try { + destinationArn = await this.getDestinationArn(logIngestionFunctionName); + } catch (err) { + this.log.error( + `Could not find a \`${logIngestionFunctionName}\` function installed.` + ); + this.log.warning( + "Details about setup requirements are available here: https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/get-started/enable-new-relic-monitoring-aws-lambda#enable-process" + ); + if (err.providerError) { + this.log.error(err.providerError.message); + } + if (!apiKey) { + this.log.error( + "Unable to create newrelic-log-ingestion because New Relic API key not configured." + ); + return; + } + + this.log.notice( + `creating required newrelic-log-ingestion function in region ${this.region}` + ); + await this.addLogIngestionFunction(); + return; + } + + let subscriptionFilters; + + try { + subscriptionFilters = await this.describeSubscriptionFilters(funcName); + } catch (err) { + if (err.providerError) { + this.log.error(err.providerError.message); + } + return; + } + + const competingFilters = subscriptionFilters.filter( + (filter) => filter.filterName !== "NewRelicLogStreaming" + ); + + if (competingFilters.length) { + this.log.warning( + "WARNING: Found a log subscription filter that was not installed by New Relic. This may prevent the New Relic log subscription filter from being installed. If you know you don't need this log subscription filter, you should first remove it and rerun this command. If your organization requires this log subscription filter, please contact New Relic at serverless@newrelic.com for assistance with getting the AWS log subscription filter limit increased." + ); + } + + const existingFilters = subscriptionFilters.filter( + (filter) => filter.filterName === "NewRelicLogStreaming" + ); + + if (existingFilters.length) { + this.log.notice( + `Found log subscription for ${funcName}, verifying configuration` + ); + + await Promise.all( + existingFilters + .filter((filter) => filter.filterPattern !== cloudWatchFilterString) + .map(async (filter) => this.removeSubscriptionFilter(funcName)) + .map(async (filter) => + this.addSubscriptionFilter( + funcName, + destinationArn, + cloudWatchFilterString + ) + ) + ); + } else { + this.log.notice(`Adding New Relic log subscription to ${funcName}`); + + await this.addSubscriptionFilter( + funcName, + destinationArn, + cloudWatchFilterString + ); + } + } + + private async addLogIngestionFunction() { + const templateUrl = await this.getSarTemplate(); + if (!templateUrl) { + this.log.error( + "Unable to create newRelic-log-ingestion without sar template." + ); + return; + } + + try { + const mode = "CREATE"; + const stackName = "NewRelicLogIngestion"; + const changeSetName = `${stackName}-${mode}-${Date.now()}`; + const parameters = await this.formatFunctionVariables(); + + const params = { + Capabilities: ["CAPABILITY_IAM"], + ChangeSetName: changeSetName, + ChangeSetType: mode, + Parameters: parameters, + StackName: stackName, + TemplateURL: templateUrl, + }; + + let cfResponse; + try { + cfResponse = await this.awsProvider.request( + "CloudFormation", + "createChangeSet", + params + ); + } catch (e) { + this.log.error(`Unable to get stack information.`); + this.log.error(e); + } + const { Id, StackId } = cfResponse; + + this.log.notice( + "Waiting for change set creation to complete, this may take a minute..." + ); + + await waitForStatus( + { + awsMethod: "describeChangeSet", + callbackMethod: () => this.executeChangeSet(Id, StackId), + methodParams: { ChangeSetName: Id }, + statusPath: "Status", + }, + this + ); + } catch (err) { + this.log.warning( + "Unable to create newrelic-log-ingestion function. Please verify that required environment variables have been set." + ); + } + } + + private async formatFunctionVariables() { + const { logEnabled } = this.config; + const licenseKey = this.licenseKey + ? this.licenseKey + : await this.retrieveLicenseKey(); + const loggingVar = logEnabled ? "True" : "False"; + + return [ + { + ParameterKey: "NRLoggingEnabled", + ParameterValue: `${loggingVar}`, + }, + { + ParameterKey: "NRLicenseKey", + ParameterValue: `${licenseKey}`, + }, + ]; + } + + private async getSarTemplate() { + try { + const data = await this.awsProvider.request( + "ServerlessApplicationRepository", + "createCloudFormationTemplate", + { + ApplicationId: + "arn:aws:serverlessrepo:us-east-1:463657938898:applications/NewRelic-log-ingestion", + } + ); + + const { TemplateUrl } = data; + return TemplateUrl; + } catch (err) { + this.log.error( + `Something went wrong while fetching the sar template: ${err}` + ); + } + } + + private async executeChangeSet(changeSetName: string, stackId: string) { + try { + await this.awsProvider.request("CloudFormation", "executeChangeSet", { + ChangeSetName: changeSetName, + }); + this.log.notice( + "Waiting for newrelic-log-ingestion install to complete, this may take a minute..." + ); + + await waitForStatus( + { + awsMethod: "describeStacks", + callbackMethod: () => this.addLogSubscriptions(), + methodParams: { StackName: stackId }, + statusPath: "Stacks[0].StackStatus", + }, + this + ); + } catch (changeSetErr) { + this.log.error( + `Something went wrong while executing the change set: ${changeSetErr}` + ); + } + } } diff --git a/tests/fixtures/arm64.output.service.json b/tests/fixtures/arm64.output.service.json index 37d1341..a5b12f4 100644 --- a/tests/fixtures/arm64.output.service.json +++ b/tests/fixtures/arm64.output.service.json @@ -24,7 +24,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16XARM64:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16XARM64:83" ], "package": { "exclude": [ @@ -52,7 +52,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18XARM64:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18XARM64:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/debug-log-level.output.service.json b/tests/fixtures/debug-log-level.output.service.json index 279d976..531db34 100644 --- a/tests/fixtures/debug-log-level.output.service.json +++ b/tests/fixtures/debug-log-level.output.service.json @@ -32,7 +32,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -54,7 +54,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/debug.output.service.json b/tests/fixtures/debug.output.service.json index c8aa74d..1336676 100644 --- a/tests/fixtures/debug.output.service.json +++ b/tests/fixtures/debug.output.service.json @@ -31,7 +31,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -53,7 +53,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/distributed-tracing-enabled.output.service.json b/tests/fixtures/distributed-tracing-enabled.output.service.json index fc05d2a..50e310c 100644 --- a/tests/fixtures/distributed-tracing-enabled.output.service.json +++ b/tests/fixtures/distributed-tracing-enabled.output.service.json @@ -26,7 +26,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -50,7 +50,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/eu.output.service.json b/tests/fixtures/eu.output.service.json index 97fc493..c438c79 100644 --- a/tests/fixtures/eu.output.service.json +++ b/tests/fixtures/eu.output.service.json @@ -29,7 +29,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -55,7 +55,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/function-has-layers.output.service.json b/tests/fixtures/function-has-layers.output.service.json index 0824403..6383054 100644 --- a/tests/fixtures/function-has-layers.output.service.json +++ b/tests/fixtures/function-has-layers.output.service.json @@ -2,7 +2,7 @@ "service": "newrelic-lambda-layers-nodejs-example", "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "stage": "prod", @@ -46,7 +46,7 @@ "runtime": "nodejs18.x", "layers": [ "arn:aws:lambda:us-east-1:123456789012:layer:SomeOtherLayer:1", - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ] }, "layer-nodejs18x2": { diff --git a/tests/fixtures/include.output.service.json b/tests/fixtures/include.output.service.json index 9b3b936..fde86e3 100644 --- a/tests/fixtures/include.output.service.json +++ b/tests/fixtures/include.output.service.json @@ -43,7 +43,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ "./**", diff --git a/tests/fixtures/includes-all-provider-layer.output.service.json b/tests/fixtures/includes-all-provider-layer.output.service.json index 7bd6f83..09d4360 100644 --- a/tests/fixtures/includes-all-provider-layer.output.service.json +++ b/tests/fixtures/includes-all-provider-layer.output.service.json @@ -2,7 +2,7 @@ "service": "newrelic-lambda-layers-nodejs-example", "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "stage": "prod", diff --git a/tests/fixtures/lambda-extension-disabled.output.service.json b/tests/fixtures/lambda-extension-disabled.output.service.json index 15cfb61..fa9c47d 100644 --- a/tests/fixtures/lambda-extension-disabled.output.service.json +++ b/tests/fixtures/lambda-extension-disabled.output.service.json @@ -25,7 +25,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -49,7 +49,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/lambda-extension-enabled.output.service.json b/tests/fixtures/lambda-extension-enabled.output.service.json index 81f09c5..7cffb6c 100644 --- a/tests/fixtures/lambda-extension-enabled.output.service.json +++ b/tests/fixtures/lambda-extension-enabled.output.service.json @@ -24,7 +24,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -47,7 +47,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/license-key-secret-disabled.output.service.json b/tests/fixtures/license-key-secret-disabled.output.service.json index 1ce3712..320058a 100644 --- a/tests/fixtures/license-key-secret-disabled.output.service.json +++ b/tests/fixtures/license-key-secret-disabled.output.service.json @@ -25,7 +25,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": [ @@ -53,7 +53,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/log-disabled.output.service.json b/tests/fixtures/log-disabled.output.service.json index ddf3567..302b7ec 100644 --- a/tests/fixtures/log-disabled.output.service.json +++ b/tests/fixtures/log-disabled.output.service.json @@ -31,7 +31,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -50,7 +50,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/log-ingestion-via-extension.output.service.json b/tests/fixtures/log-ingestion-via-extension.output.service.json index ec63f9a..c3bc88b 100644 --- a/tests/fixtures/log-ingestion-via-extension.output.service.json +++ b/tests/fixtures/log-ingestion-via-extension.output.service.json @@ -28,7 +28,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": [ @@ -57,7 +57,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/log-level.output.service.json b/tests/fixtures/log-level.output.service.json index 52c2851..51bfcfb 100644 --- a/tests/fixtures/log-level.output.service.json +++ b/tests/fixtures/log-level.output.service.json @@ -31,7 +31,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -53,7 +53,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/manual-wrapping.output.service.json b/tests/fixtures/manual-wrapping.output.service.json index 369cdcb..3082eaa 100644 --- a/tests/fixtures/manual-wrapping.output.service.json +++ b/tests/fixtures/manual-wrapping.output.service.json @@ -40,7 +40,7 @@ ], "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "region": "us-east-1", diff --git a/tests/fixtures/node-versions.output.service.json b/tests/fixtures/node-versions.output.service.json index c53eabf..11f149a 100644 --- a/tests/fixtures/node-versions.output.service.json +++ b/tests/fixtures/node-versions.output.service.json @@ -29,7 +29,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -48,7 +48,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -67,7 +67,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS20X:5" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS20X:8" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/provider-environment-log-level.output.service.json b/tests/fixtures/provider-environment-log-level.output.service.json index 0b1622c..a196ebd 100644 --- a/tests/fixtures/provider-environment-log-level.output.service.json +++ b/tests/fixtures/provider-environment-log-level.output.service.json @@ -34,7 +34,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -56,7 +56,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/provider-environment.output.service.json b/tests/fixtures/provider-environment.output.service.json index dca5925..a69d2c7 100644 --- a/tests/fixtures/provider-environment.output.service.json +++ b/tests/fixtures/provider-environment.output.service.json @@ -33,7 +33,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -55,7 +55,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/provider-layer.output.service.json b/tests/fixtures/provider-layer.output.service.json index b0e93db..305b999 100644 --- a/tests/fixtures/provider-layer.output.service.json +++ b/tests/fixtures/provider-layer.output.service.json @@ -2,7 +2,7 @@ "service": "newrelic-lambda-layers-nodejs-example", "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "stage": "prod", diff --git a/tests/fixtures/proxy.output.service.json b/tests/fixtures/proxy.output.service.json index 66522e4..f3e50dc 100644 --- a/tests/fixtures/proxy.output.service.json +++ b/tests/fixtures/proxy.output.service.json @@ -24,7 +24,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": [ @@ -52,7 +52,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/stage-included.output.service.json b/tests/fixtures/stage-included.output.service.json index 3887af3..7e0502f 100644 --- a/tests/fixtures/stage-included.output.service.json +++ b/tests/fixtures/stage-included.output.service.json @@ -30,7 +30,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -49,7 +49,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/trusted-account-key-excluded.output.service.json b/tests/fixtures/trusted-account-key-excluded.output.service.json index b2e86d3..9eea824 100644 --- a/tests/fixtures/trusted-account-key-excluded.output.service.json +++ b/tests/fixtures/trusted-account-key-excluded.output.service.json @@ -29,7 +29,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -48,7 +48,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/trusted-account-key-included.output.service.json b/tests/fixtures/trusted-account-key-included.output.service.json index 7f877c4..9838e87 100644 --- a/tests/fixtures/trusted-account-key-included.output.service.json +++ b/tests/fixtures/trusted-account-key-included.output.service.json @@ -30,7 +30,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -49,7 +49,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/integration.test.ts b/tests/integration.test.ts index 35b6a68..6bd11df 100644 --- a/tests/integration.test.ts +++ b/tests/integration.test.ts @@ -13,25 +13,38 @@ const logShim = { }; // for simulating AWS ListPolicies, just one per page in this test -const requestResults = require("./paginatedResults.json"); +const policiesFixture = require("./paginatedPoliciesList.json"); +const functionsFixture = require("./paginatedFunctionsList.json"); + +const setRequestEnv = (service, method) => { + let fixture = policiesFixture + if (service === 'Lambda' || method === 'listFunctions') { + fixture = functionsFixture + } + return { fixture } +} const returnPaginatedAwsRequest = (service, method, params) => { + const { fixture } = setRequestEnv(service, method) if (!params.Marker) { - return requestResults.paginated.first; + return fixture.paginated.first; } - return requestResults.paginated[params.Marker]; + return fixture.paginated[params.Marker]; }; const returnPaginatedNoMatchAwsRequest = (service, method, params) => { + const { fixture } = setRequestEnv(service, method) if (!params.Marker) { - return requestResults.paginatedNoMatch.first; + return fixture.paginatedNoMatch.first; } - return requestResults.paginatedNoMatch[params.Marker]; + return fixture.paginatedNoMatch[params.Marker]; }; -const returnNonPaginatedAwsRequest = (service, method, params) => { - return requestResults.nonPaginated; +const returnNonPaginatedAwsRequest = (service, method) => { + const { fixture } = setRequestEnv(service, method) + return fixture.nonPaginated; }; -const returnNonPaginatedNoMatchAwsRequest = (service, method, params) => { - return requestResults.nonPaginatedNoMatch; +const returnNonPaginatedNoMatchAwsRequest = (service, method) => { + const { fixture } = setRequestEnv(service, method) + return fixture.nonPaginatedNoMatch; }; describe("Integration functions", () => { @@ -66,7 +79,7 @@ describe("Integration functions", () => { "PolicyName", ]); expect(existingPolicy.currentRegionPolicy[0].PolicyName).toEqual( - requestResults.paginated.fourth.Policies[0].PolicyName + policiesFixture.paginated.fourth.Policies[0].PolicyName ); expect(existingPolicy.secretExists).toBeTruthy(); }); @@ -82,7 +95,7 @@ describe("Integration functions", () => { "PolicyName", ]); expect(existingPolicy.currentRegionPolicy[0].PolicyName).toEqual( - requestResults.paginated.fourth.Policies[0].PolicyName + policiesFixture.paginated.fourth.Policies[0].PolicyName ); expect(existingPolicy.secretExists).toBeTruthy(); }); @@ -107,4 +120,40 @@ describe("Integration functions", () => { expect(existingPolicy.secretExists).toBeFalsy(); }); }); + describe("search for existing log ingestion function", () => { + it("correctly finds match in multiple pages of results", async () => { + awsProvider.request = jest.fn(returnPaginatedAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeDefined(); + expect(existingIngestScript).toEqual( + functionsFixture.paginated.fourth.Functions[0].FunctionArn + ); + }); + it("correctly finds match in non-paginated results", async () => { + awsProvider.request = jest.fn(returnNonPaginatedAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeDefined(); + expect(existingIngestScript).toEqual( + functionsFixture.paginated.fourth.Functions[0].FunctionArn + ); + }); + it("correctly handles paginated results with no match", async () => { + awsProvider.request = jest.fn(returnPaginatedNoMatchAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeFalsy(); + }); + it("correctly handles non-paginated results with no match", async () => { + awsProvider.request = jest.fn(returnNonPaginatedNoMatchAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeFalsy(); + }); + }); }); diff --git a/tests/paginatedFunctionsList.json b/tests/paginatedFunctionsList.json new file mode 100644 index 0000000..aa57bd3 --- /dev/null +++ b/tests/paginatedFunctionsList.json @@ -0,0 +1,120 @@ +{ + "paginated": { + "first": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName" + } + ], + "NextMarker": "second" + }, + "second": { + "Functions": [ + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName" + } + ], + "NextMarker": "third" + }, + "third": { + "Functions": [ + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName" + } + ], + "NextMarker": "fourth" + }, + "fourth": { + "Functions": [ + { + "FunctionName": "newrelic-log-ingestion-0123456789ab", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:newrelic-log-ingestion-0123456789ab" + } + ] + } + }, + "paginatedNoMatch": { + "first": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName" + } + ], + "NextMarker": "second" + }, + "second": { + "Functions": [ + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName" + } + ], + "NextMarker": "third" + }, + "third": { + "Functions": [ + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName" + } + ], + "NextMarker": "fourth" + }, + "fourth": { + "Functions": [ + { + "FunctionName": "FourthFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:policy/FourthFunctionName" + } + ] + } + }, + "nonPaginated": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName" + }, + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName" + }, + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName" + }, + { + "FunctionName": "newrelic-log-ingestion-0123456789ab", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:newrelic-log-ingestion-0123456789ab" + } + ] + }, + "nonPaginatedNoMatch": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName", + "Path": "/service-role/" + }, + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName", + "Path": "/service-role/" + }, + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName", + "Path": "/service-role/" + }, + { + "FunctionName": "FourthFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:policy/FourthFunctionName", + "Path": "/" + } + ] + } +} diff --git a/tests/paginatedResults.json b/tests/paginatedPoliciesList.json similarity index 100% rename from tests/paginatedResults.json rename to tests/paginatedPoliciesList.json