Skip to content

Commit

Permalink
Merge pull request #116 from bobomoirang/master
Browse files Browse the repository at this point in the history
Added disableLicenseKeySecret flag
  • Loading branch information
mrickard authored Mar 5, 2021
2 parents 0f32340 + 528358e commit 141e444
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 73 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ custom:
disableAutoSubscription: true
```

#### `disableLicenseKeySecret` (optional)

Only required if you want to disable creating license key in AWS Secrets Manager. Setting this as `true` would create NEW_RELIC_LICENSE_KEY environment variable for the New Relic Lambda Extension to access.

```yaml
custom:
newRelic:
disableLicenseKeySecret: true
```

## Supported Runtimes

This plugin currently supports the following AWS runtimes:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-newrelic-lambda-layers",
"version": "1.1.4",
"version": "1.1.5",
"description": "Serverless plugin for NewRelic APM AWS Lambda layers.",
"main": "dist/index.js",
"files": [
Expand Down
65 changes: 41 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export default class NewRelicLambdaLayerPlugin {
);
}

get licenseKeySecretDisabled() {
return (
typeof this.config.disableLicenseKeySecret === "boolean" &&
this.config.disableLicenseKeySecret
);
}

get functions() {
return Object.assign.apply(
null,
Expand Down Expand Up @@ -154,27 +161,33 @@ https://blog.newrelic.com/product-news/aws-lambda-extensions-integrations/
}
}

// If the managed secret has already been created,
// there should be policies for it.
const secretAccess = await this.checkForSecretPolicy();
let managedSecret;
if (!this.licenseKeySecretDisabled) {
// If the managed secret has already been created,
// there should be policies for it.
const secretAccess = await this.checkForSecretPolicy();
let managedSecret;

if (secretAccess.secretExists) {
this.managedSecretConfigured = true;
} else {
// Secret doesn't exist, so create it
managedSecret = await new Integration(this).createManagedSecret();
if (managedSecret && managedSecret.policyArn) {
if (secretAccess.secretExists) {
this.managedSecretConfigured = true;
} else {
// Secret doesn't exist, so create it
managedSecret = await new Integration(this).createManagedSecret();
if (managedSecret && managedSecret.policyArn) {
this.managedSecretConfigured = true;
}
}
}

if (secretAccess.currentRegionPolicy.length > 0) {
const policyArn = secretAccess.currentRegionPolicy[0].Arn;
this.mgdPolicyArns = [...this.managedPolicyArns, policyArn];
} else if (this.managedSecretConfigured) {
this.mgdPolicyArns = [...this.managedPolicyArns, managedSecret.policyArn];
if (secretAccess.currentRegionPolicy.length > 0) {
const policyArn = secretAccess.currentRegionPolicy[0].Arn;
this.mgdPolicyArns = [...this.managedPolicyArns, policyArn];
} else if (this.managedSecretConfigured) {
this.mgdPolicyArns = [
...this.managedPolicyArns,
managedSecret.policyArn
];
}
}

return;
}

Expand Down Expand Up @@ -222,14 +235,18 @@ https://blog.newrelic.com/product-news/aws-lambda-extensions-integrations/
await this.configureLicenseForExtension();
}

// before adding layer, attach secret access policy
// to each function's execution role:
const resources = this.resources;
Object.keys(resources)
.filter(resourceName => resources[resourceName].Type === `AWS::IAM::Role`)
.forEach(roleResource =>
this.applyPolicies(resources[roleResource].Properties)
);
if (!this.licenseKeySecretDisabled) {
// before adding layer, attach secret access policy
// to each function's execution role:
const resources = this.resources;
Object.keys(resources)
.filter(
resourceName => resources[resourceName].Type === `AWS::IAM::Role`
)
.forEach(roleResource =>
this.applyPolicies(resources[roleResource].Properties)
);
}

const funcs = this.functions;
const promises = [];
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/debug-log-level.output.service.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-wrapper-helper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -55,7 +55,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:33"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:37"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -78,7 +78,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -101,7 +101,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:1"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:5"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/debug.output.service.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-wrapper-helper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -54,7 +54,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:33"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:37"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -77,7 +77,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -100,7 +100,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:1"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:5"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:32"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:37"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -53,7 +53,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:30"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -78,7 +78,7 @@
],
"handler": "newrelic-wrapper-helper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:30"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/eu.output.service.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:33"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:37"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -57,7 +57,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -84,7 +84,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:1"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:5"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -111,7 +111,7 @@
],
"handler": "newrelic-wrapper-helper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/include.output.service.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "newrelic-wrapper-helper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/lambda-extension-disabled.output.service.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:33"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:37"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -49,7 +49,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -73,7 +73,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:1"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:5"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -97,7 +97,7 @@
],
"handler": "newrelic-wrapper-helper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/lambda-extension-enabled.output.service.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:33"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS10X:37"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -50,7 +50,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS12X:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -74,7 +74,7 @@
],
"handler": "newrelic-lambda-wrapper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:1"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:5"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand All @@ -98,7 +98,7 @@
],
"handler": "newrelic-wrapper-helper.handler",
"layers": [
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:31"
"arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS810:35"
],
"package": {
"exclude": ["./**", "!newrelic-wrapper-helper.js"],
Expand Down
53 changes: 53 additions & 0 deletions tests/fixtures/license-key-secret-disabled.input.service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"service": "newrelic-lambda-layers-nodejs-example",
"provider": {
"name": "aws",
"stage": "prod",
"region": "us-east-1",
"stackTags": {
"environment": "us-testing",
"owning_team": "LAMBDA",
"product": "aws-lambda"
},
"tags": {
"environment": "us-testing",
"owning_team": "LAMBDA",
"product": "aws-lambda"
}
},
"plugins": ["serverless-newrelic-lambda-layers"],
"custom": {
"newRelic": {
"accountId": "${env:NEW_RELIC_ACCOUNT_ID}",
"apiKey": "${env:NEW_RELIC_PERSONAL_API_KEY}",
"logLevel": "debug",
"disableLicenseKeySecret": false
}
},
"functions": {
"layer-nodejs810": {
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "handler.handler",
"package": { "exclude": ["./**"], "include": ["handler.js"] },
"runtime": "nodejs8.10"
},
"layer-nodejs10x": {
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "handler.handler",
"package": { "exclude": ["./**"], "include": ["handler.js"] },
"runtime": "nodejs10.x"
},
"layer-nodejs12x": {
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "handler.handler",
"package": { "exclude": ["./**"], "include": ["handler.js"] },
"runtime": "nodejs12.x"
},
"layer-nodejs14x": {
"events": [{ "schedule": "rate(5 minutes)" }],
"handler": "handler.handler",
"package": { "exclude": ["./**"], "include": ["handler.js"] },
"runtime": "nodejs14.x"
}
}
}
Loading

0 comments on commit 141e444

Please sign in to comment.