newrelic-lambda-cli 0.9.9__tar.gz → 0.9.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/PKG-INFO +11 -2
  2. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/README.md +10 -1
  3. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/api.py +8 -4
  4. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cli/layers.py +49 -4
  5. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/layers.py +68 -8
  6. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/types.py +8 -0
  7. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/utils.py +3 -1
  8. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli.egg-info/PKG-INFO +11 -2
  9. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/setup.py +1 -1
  10. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_layers.py +661 -10
  11. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/CODE_OF_CONDUCT.md +0 -0
  12. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/CONTRIBUTING.md +0 -0
  13. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/LICENSE +0 -0
  14. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/MANIFEST.in +0 -0
  15. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/THIRD_PARTY_NOTICES.md +0 -0
  16. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/__init__.py +0 -0
  17. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cli/__init__.py +0 -0
  18. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cli/decorators.py +0 -0
  19. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cli/functions.py +0 -0
  20. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cli/integrations.py +0 -0
  21. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cli/otel_ingestions.py +0 -0
  22. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cli/subscriptions.py +0 -0
  23. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/cliutils.py +0 -0
  24. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/functions.py +0 -0
  25. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/integrations.py +0 -0
  26. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/otel_ingestions.py +0 -0
  27. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/permissions.py +0 -0
  28. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/subscriptions.py +0 -0
  29. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/templates/import-template.yaml +0 -0
  30. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/templates/license-key-secret.yaml +0 -0
  31. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli/templates/nr-lambda-integration-role.yaml +0 -0
  32. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli.egg-info/SOURCES.txt +0 -0
  33. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli.egg-info/dependency_links.txt +0 -0
  34. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli.egg-info/entry_points.txt +0 -0
  35. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli.egg-info/not-zip-safe +0 -0
  36. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli.egg-info/requires.txt +0 -0
  37. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/newrelic_lambda_cli.egg-info/top_level.txt +0 -0
  38. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/pyproject.toml +0 -0
  39. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/setup.cfg +0 -0
  40. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_api.py +0 -0
  41. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_functions.py +0 -0
  42. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_integrations.py +0 -0
  43. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_new_relic_gql.py +0 -0
  44. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_permissions.py +0 -0
  45. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_subscriptions.py +0 -0
  46. {newrelic_lambda_cli-0.9.9 → newrelic_lambda_cli-0.9.11}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: newrelic-lambda-cli
3
- Version: 0.9.9
3
+ Version: 0.9.11
4
4
  Summary: A CLI to install the New Relic AWS Lambda integration and layers.
5
5
  Home-page: https://github.com/newrelic/newrelic-lambda-cli
6
6
  Author: New Relic
@@ -126,6 +126,9 @@ newrelic-lambda integrations install \
126
126
  | `--nr-api-key` or `-k` | Yes | Your [New Relic User API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key). Can also use the `NEW_RELIC_API_KEY` environment variable. |
127
127
  | `--linked-account-name` or `-n` | No | A label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - <AWS Account ID>". |
128
128
  | `--enable-logs` or `-e` | No | Enables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run `newrelic-lambda subscriptions install --function ... --filter-pattern ""` afterwards. |
129
+ | `--enable-license-key-secret` | No | Securely manages and store your New Relic license key in `AWS Secrets Manager` |
130
+ | `--enable-cw-ingest` | No | Enable the CloudWatch `log ingest` function |
131
+ | `--disable-cw-ingest` | No | Disable the CloudWatch `log ingest` function |
129
132
  | `--memory-size` or `-m` | No | Memory size (in MiB) for the New Relic log ingestion function. Default to 128MB. |
130
133
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. |
131
134
  | `--timeout` or `-t` | No | Timeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds. |
@@ -171,6 +174,7 @@ newrelic-lambda integrations update \
171
174
  | `--disable-logs` or `-d` | No | Disables forwarding logs to New Relic Logging. Make sure you run `newrelic-lambda subscriptions install --function ...` afterwards. |
172
175
  | `--enable-logs` or `-e` | No | Enables forwarding logs to New Relic Logging. Make sure you run `newrelic-lambda subscriptions install --function ... --filter-pattern ""` afterwards. |
173
176
  | `--memory-size` or `-m` | No | Memory size (in MiB) for the New Relic log ingestion function. |
177
+ | `--enable-license-key-secret` | No | Securely manages and store your New Relic license key in `AWS Secrets Manager` |
174
178
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. |
175
179
  | `--timeout` or `-t` | No | Timeout (in seconds) for the New Relic log ingestion function. |
176
180
  | `--role-name` | No | Role name for the ingestion function. If you prefer to create and manage an IAM role for the function to assume out of band, do so and specify that role's name here. This avoids needing CAPABILITY_IAM. |
@@ -198,11 +202,16 @@ newrelic-lambda layers install \
198
202
  | `--layer-arn` or `-l` | No | Specify a specific layer version ARN to use. This is auto detected by default. |
199
203
  | `--upgrade` or `-u` | No | Permit upgrade to the latest layer version for this region and runtime. |
200
204
  | `--disable-extension` | No | Disable the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). |
201
- | `--enable-extension-function-logs` | No | Enable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
205
+ | `--enable-extension-function-logs` or `--send-function-logs` | No | Enable sending Lambda function logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
206
+ | `--disable-extension-function-logs` or `--disable-function-logs` | No | Disable sending Lambda function logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension).|
207
+ | `--send-extension-logs` | No | Enable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
208
+ | `--disable-extension-logs` | No | Disable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension).|
202
209
  | `--aws-profile` or `-p` | No | The AWS profile to use for this command. Can also use `AWS_PROFILE`. Will also check `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables if not using AWS CLI. |
203
210
  | `--aws-region` or `-r` | No | The AWS region this function is located. Can use `AWS_DEFAULT_REGION` environment variable. Defaults to AWS session region. |
204
211
  | `--nr-api-key` or `-k` | No | Your [New Relic User API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key). Can also use the `NEW_RELIC_API_KEY` environment variable. Only used if `--enable-extension` is set and there is no New Relic license key in AWS Secrets Manager. |
205
212
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. Only used if `--enable-extension` is set and there is no New Relic license key in AWS Secrets Manager. |
213
+ | `--nr-env-delimite` | No | Set `NR_ENV_DELIMITER` environment variable for your Lambda Function |
214
+ | `--nr-tags` | No | Set `NR_TAGS` environment variable for your Lambda Function |
206
215
  | `--java_handler_method` or `-j` | No | For java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest `--java_handler_method handleStreamsRequest`. |
207
216
  | `--esm` | No | For Node.js functions using ES Modules (ESM), enable the specific ESM wrapper during installation (e.g., using the --esm flag). This sets the Lambda handler to `/opt/nodejs/node_modules/newrelic-esm-lambda-wrapper/index.handler`. |
208
217
 
@@ -100,6 +100,9 @@ newrelic-lambda integrations install \
100
100
  | `--nr-api-key` or `-k` | Yes | Your [New Relic User API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key). Can also use the `NEW_RELIC_API_KEY` environment variable. |
101
101
  | `--linked-account-name` or `-n` | No | A label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - <AWS Account ID>". |
102
102
  | `--enable-logs` or `-e` | No | Enables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run `newrelic-lambda subscriptions install --function ... --filter-pattern ""` afterwards. |
103
+ | `--enable-license-key-secret` | No | Securely manages and store your New Relic license key in `AWS Secrets Manager` |
104
+ | `--enable-cw-ingest` | No | Enable the CloudWatch `log ingest` function |
105
+ | `--disable-cw-ingest` | No | Disable the CloudWatch `log ingest` function |
103
106
  | `--memory-size` or `-m` | No | Memory size (in MiB) for the New Relic log ingestion function. Default to 128MB. |
104
107
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. |
105
108
  | `--timeout` or `-t` | No | Timeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds. |
@@ -145,6 +148,7 @@ newrelic-lambda integrations update \
145
148
  | `--disable-logs` or `-d` | No | Disables forwarding logs to New Relic Logging. Make sure you run `newrelic-lambda subscriptions install --function ...` afterwards. |
146
149
  | `--enable-logs` or `-e` | No | Enables forwarding logs to New Relic Logging. Make sure you run `newrelic-lambda subscriptions install --function ... --filter-pattern ""` afterwards. |
147
150
  | `--memory-size` or `-m` | No | Memory size (in MiB) for the New Relic log ingestion function. |
151
+ | `--enable-license-key-secret` | No | Securely manages and store your New Relic license key in `AWS Secrets Manager` |
148
152
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. |
149
153
  | `--timeout` or `-t` | No | Timeout (in seconds) for the New Relic log ingestion function. |
150
154
  | `--role-name` | No | Role name for the ingestion function. If you prefer to create and manage an IAM role for the function to assume out of band, do so and specify that role's name here. This avoids needing CAPABILITY_IAM. |
@@ -172,11 +176,16 @@ newrelic-lambda layers install \
172
176
  | `--layer-arn` or `-l` | No | Specify a specific layer version ARN to use. This is auto detected by default. |
173
177
  | `--upgrade` or `-u` | No | Permit upgrade to the latest layer version for this region and runtime. |
174
178
  | `--disable-extension` | No | Disable the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). |
175
- | `--enable-extension-function-logs` | No | Enable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
179
+ | `--enable-extension-function-logs` or `--send-function-logs` | No | Enable sending Lambda function logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
180
+ | `--disable-extension-function-logs` or `--disable-function-logs` | No | Disable sending Lambda function logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension).|
181
+ | `--send-extension-logs` | No | Enable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
182
+ | `--disable-extension-logs` | No | Disable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension).|
176
183
  | `--aws-profile` or `-p` | No | The AWS profile to use for this command. Can also use `AWS_PROFILE`. Will also check `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables if not using AWS CLI. |
177
184
  | `--aws-region` or `-r` | No | The AWS region this function is located. Can use `AWS_DEFAULT_REGION` environment variable. Defaults to AWS session region. |
178
185
  | `--nr-api-key` or `-k` | No | Your [New Relic User API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key). Can also use the `NEW_RELIC_API_KEY` environment variable. Only used if `--enable-extension` is set and there is no New Relic license key in AWS Secrets Manager. |
179
186
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. Only used if `--enable-extension` is set and there is no New Relic license key in AWS Secrets Manager. |
187
+ | `--nr-env-delimite` | No | Set `NR_ENV_DELIMITER` environment variable for your Lambda Function |
188
+ | `--nr-tags` | No | Set `NR_TAGS` environment variable for your Lambda Function |
180
189
  | `--java_handler_method` or `-j` | No | For java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest `--java_handler_method handleStreamsRequest`. |
181
190
  | `--esm` | No | For Node.js functions using ES Modules (ESM), enable the specific ESM wrapper during installation (e.g., using the --esm flag). This sets the Lambda handler to `/opt/nodejs/node_modules/newrelic-esm-lambda-wrapper/index.handler`. |
182
191
 
@@ -362,6 +362,9 @@ def validate_gql_credentials(input):
362
362
 
363
363
  def retrieve_license_key(gql):
364
364
  global __cached_license_key
365
+ if gql is None and input and getattr(input, "nr_ingest_key", None):
366
+ return input.nr_ingest_key
367
+
365
368
  if __cached_license_key:
366
369
  return __cached_license_key
367
370
  assert isinstance(gql, NewRelicGQL)
@@ -370,11 +373,12 @@ def retrieve_license_key(gql):
370
373
  return __cached_license_key
371
374
  except Exception:
372
375
  raise click.BadParameter(
373
- "Could not retrieve license key from New Relic. Check that your New Relic "
374
- "Account ID is valid and try again.",
376
+ f"For New Relic Account ID: {gql.account_id}. "
377
+ "Could not retrieve INGEST - LICENSE key from New Relic. "
378
+ "Check that your New Relic Account ID and USER key are valid and try again.",
375
379
  ctx=None,
376
- param="nr_account_id",
377
- param_hint="New Relic Account ID",
380
+ param="nr_api_key",
381
+ param_hint="API Key",
378
382
  )
379
383
 
380
384
 
@@ -42,6 +42,13 @@ def register(group):
42
42
  metavar="<key>",
43
43
  required=False,
44
44
  )
45
+ @click.option(
46
+ "--nr-ingest-key",
47
+ envvar="NEW_RELIC_INGEST_KEY",
48
+ help="New Relic License/Ingest Key (alternative to --nr-api-key)",
49
+ metavar="<key>",
50
+ required=False,
51
+ )
45
52
  @click.option(
46
53
  "--nr-region",
47
54
  default="us",
@@ -94,10 +101,42 @@ def register(group):
94
101
  help="Enable/disable the New Relic Lambda Extension",
95
102
  )
96
103
  @click.option(
97
- "--enable-extension-function-logs/--disable-extension-function-logs",
98
- default=False,
99
- show_default=True,
100
- help="Enable/disable sending Lambda function logs via the Extension",
104
+ "--send-extension-logs",
105
+ is_flag=True,
106
+ help="Enable sending extension logs via the New Relic Lambda Extension",
107
+ )
108
+ @click.option(
109
+ "--disable-extension-logs",
110
+ is_flag=True,
111
+ help="Disable sending extension logs via the New Relic Lambda Extension",
112
+ )
113
+ @click.option(
114
+ "--enable-extension-function-logs",
115
+ is_flag=True,
116
+ help="Enable sending Lambda function logs via the New Relic Lambda Extension",
117
+ )
118
+ @click.option(
119
+ "--disable-extension-function-logs",
120
+ is_flag=True,
121
+ help="Disable sending Lambda function logs via the New Relic Lambda Extension",
122
+ )
123
+ @click.option(
124
+ "--nr-tags",
125
+ help="Set NR_TAGS environment variable for Lambda (e.g. key1:value1;key2:value2)",
126
+ )
127
+ @click.option(
128
+ "--nr-env-delimiter",
129
+ help="Set NR_ENV_DELIMITER environment variable for Lambda (e.g. ',' for comma)",
130
+ )
131
+ @click.option(
132
+ "--send-function-logs",
133
+ is_flag=True,
134
+ help="Enable sending Lambda function logs via the New Relic Lambda Extension",
135
+ )
136
+ @click.option(
137
+ "--disable-function-logs",
138
+ is_flag=True,
139
+ help="Disable sending Lambda function logs via the New Relic Lambda Extension",
101
140
  )
102
141
  @click.option(
103
142
  "--java_handler_method",
@@ -116,6 +155,12 @@ def register(group):
116
155
  @click.pass_context
117
156
  def install(ctx, **kwargs):
118
157
  """Install New Relic AWS Lambda Layers"""
158
+
159
+ if "nr_ingest_key" not in kwargs:
160
+ kwargs["nr_ingest_key"] = None
161
+ if "nr_api_key" not in kwargs:
162
+ kwargs["nr_api_key"] = None
163
+
119
164
  input = LayerInstall(session=None, verbose=ctx.obj["VERBOSE"], **kwargs)
120
165
  input = input._replace(
121
166
  session=boto3.Session(
@@ -18,6 +18,7 @@ from newrelic_lambda_cli.utils import catch_boto_errors
18
18
 
19
19
  NEW_RELIC_ENV_VARS = (
20
20
  "NEW_RELIC_ACCOUNT_ID",
21
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS",
21
22
  "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS",
22
23
  "NEW_RELIC_LAMBDA_EXTENSION_ENABLED",
23
24
  "NEW_RELIC_LAMBDA_HANDLER",
@@ -25,6 +26,8 @@ NEW_RELIC_ENV_VARS = (
25
26
  "NEW_RELIC_LOG_ENDPOINT",
26
27
  "NEW_RELIC_TELEMETRY_ENDPOINT",
27
28
  "NEW_RELIC_APM_LAMBDA_MODE",
29
+ "NR_TAGS",
30
+ "NR_ENV_DELIMITER",
28
31
  )
29
32
 
30
33
 
@@ -201,10 +204,52 @@ def _add_new_relic(input, config, nr_license_key):
201
204
  "NEW_RELIC_LAMBDA_EXTENSION_ENABLED"
202
205
  ] = "true"
203
206
 
204
- update_kwargs["Environment"]["Variables"][
205
- "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
206
- ] = ("true" if input.enable_extension_function_logs else "false")
207
+ if not input.upgrade:
208
+ update_kwargs["Environment"]["Variables"][
209
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
210
+ ] = "false"
211
+ elif input.enable_extension_function_logs or input.send_function_logs:
212
+ update_kwargs["Environment"]["Variables"][
213
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
214
+ ] = "true"
215
+ success(
216
+ "Successfully enabled NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS tag to the function"
217
+ )
218
+ elif input.disable_extension_function_logs or input.disable_function_logs:
219
+ update_kwargs["Environment"]["Variables"][
220
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
221
+ ] = "false"
222
+ success(
223
+ "Successfully disabled NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS tag to the function"
224
+ )
225
+
226
+ if not input.upgrade:
227
+ update_kwargs["Environment"]["Variables"][
228
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
229
+ ] = "false"
230
+ elif input.send_extension_logs:
231
+ update_kwargs["Environment"]["Variables"][
232
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
233
+ ] = "true"
234
+ success(
235
+ "Successfully enabled NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS tag to the function"
236
+ )
237
+ elif input.disable_extension_logs:
238
+ update_kwargs["Environment"]["Variables"][
239
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
240
+ ] = "false"
241
+ success(
242
+ "Successfully disabled NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS tag to the function"
243
+ )
207
244
 
245
+ if input.nr_tags:
246
+ update_kwargs["Environment"]["Variables"]["NR_TAGS"] = input.nr_tags
247
+ success("Successfully added NR_TAGS tag to the function")
248
+ if input.nr_env_delimiter:
249
+ update_kwargs["Environment"]["Variables"][
250
+ "NR_ENV_DELIMITER"
251
+ ] = input.nr_env_delimiter
252
+ success("Successfully added NR_ENV_DELIMITER tag to the function")
208
253
  if input.nr_region == "staging":
209
254
  update_kwargs["Environment"]["Variables"][
210
255
  "NEW_RELIC_TELEMETRY_ENDPOINT"
@@ -213,14 +258,19 @@ def _add_new_relic(input, config, nr_license_key):
213
258
  "NEW_RELIC_LOG_ENDPOINT"
214
259
  ] = "https://staging-log-api.newrelic.com/log/v1"
215
260
 
216
- if nr_license_key:
261
+ if input.nr_ingest_key:
262
+ update_kwargs["Environment"]["Variables"][
263
+ "NEW_RELIC_LICENSE_KEY"
264
+ ] = input.nr_ingest_key
265
+ success("Using New Relic ingest key for layer configuration")
266
+ elif nr_license_key:
217
267
  update_kwargs["Environment"]["Variables"][
218
268
  "NEW_RELIC_LICENSE_KEY"
219
269
  ] = nr_license_key
220
- else:
221
- update_kwargs["Environment"]["Variables"][
222
- "NEW_RELIC_LAMBDA_EXTENSION_ENABLED"
223
- ] = "false"
270
+ else:
271
+ update_kwargs["Environment"]["Variables"][
272
+ "NEW_RELIC_LAMBDA_EXTENSION_ENABLED"
273
+ ] = "false"
224
274
 
225
275
  if "dotnet" in runtime:
226
276
  update_kwargs["Environment"]["Variables"]["CORECLR_ENABLE_PROFILING"] = "1"
@@ -246,6 +296,14 @@ def _add_new_relic(input, config, nr_license_key):
246
296
 
247
297
  @catch_boto_errors
248
298
  def install(input, function_arn):
299
+ if input.nr_api_key and input.nr_ingest_key:
300
+ raise click.UsageError(
301
+ "Please provide either the --nr-api-key or the --nr-ingest-key flag, but not both."
302
+ )
303
+ if not input.nr_api_key and not input.nr_ingest_key:
304
+ raise click.UsageError(
305
+ "Please provide either the --nr-api-key or the --nr-ingest-key flag."
306
+ )
249
307
  assert isinstance(input, LayerInstall)
250
308
 
251
309
  client = input.session.client("lambda")
@@ -297,6 +355,8 @@ def install(input, function_arn):
297
355
  ):
298
356
  gql = api.validate_gql_credentials(input)
299
357
  nr_license_key = api.retrieve_license_key(gql)
358
+ elif input.nr_ingest_key:
359
+ nr_license_key = input.nr_ingest_key
300
360
 
301
361
  update_kwargs = _add_new_relic(input, config, nr_license_key)
302
362
  if isinstance(update_kwargs, bool):
@@ -96,6 +96,7 @@ LAYER_INSTALL_KEYS = [
96
96
  "verbose",
97
97
  "nr_account_id",
98
98
  "nr_api_key",
99
+ "nr_ingest_key",
99
100
  "nr_region",
100
101
  "aws_profile",
101
102
  "aws_region",
@@ -107,6 +108,13 @@ LAYER_INSTALL_KEYS = [
107
108
  "apm",
108
109
  "enable_extension",
109
110
  "enable_extension_function_logs",
111
+ "disable_extension_function_logs",
112
+ "nr_tags",
113
+ "nr_env_delimiter",
114
+ "send_function_logs",
115
+ "disable_function_logs",
116
+ "send_extension_logs",
117
+ "disable_extension_logs",
110
118
  "java_handler_method",
111
119
  "esm",
112
120
  ]
@@ -187,7 +187,9 @@ def parse_arn(arn):
187
187
  result["resource"] = elements[5]
188
188
  result["resourcetype"] = None
189
189
  else:
190
- result["resourcetype"], result["resource"] = elements[5].split("/")
190
+ splitted_arn = elements[5].split("/")
191
+ result["resourcetype"] = splitted_arn[0]
192
+ result["resource"] = "/".join(splitted_arn[1:])
191
193
  return result
192
194
 
193
195
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: newrelic-lambda-cli
3
- Version: 0.9.9
3
+ Version: 0.9.11
4
4
  Summary: A CLI to install the New Relic AWS Lambda integration and layers.
5
5
  Home-page: https://github.com/newrelic/newrelic-lambda-cli
6
6
  Author: New Relic
@@ -126,6 +126,9 @@ newrelic-lambda integrations install \
126
126
  | `--nr-api-key` or `-k` | Yes | Your [New Relic User API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key). Can also use the `NEW_RELIC_API_KEY` environment variable. |
127
127
  | `--linked-account-name` or `-n` | No | A label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - <AWS Account ID>". |
128
128
  | `--enable-logs` or `-e` | No | Enables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run `newrelic-lambda subscriptions install --function ... --filter-pattern ""` afterwards. |
129
+ | `--enable-license-key-secret` | No | Securely manages and store your New Relic license key in `AWS Secrets Manager` |
130
+ | `--enable-cw-ingest` | No | Enable the CloudWatch `log ingest` function |
131
+ | `--disable-cw-ingest` | No | Disable the CloudWatch `log ingest` function |
129
132
  | `--memory-size` or `-m` | No | Memory size (in MiB) for the New Relic log ingestion function. Default to 128MB. |
130
133
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. |
131
134
  | `--timeout` or `-t` | No | Timeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds. |
@@ -171,6 +174,7 @@ newrelic-lambda integrations update \
171
174
  | `--disable-logs` or `-d` | No | Disables forwarding logs to New Relic Logging. Make sure you run `newrelic-lambda subscriptions install --function ...` afterwards. |
172
175
  | `--enable-logs` or `-e` | No | Enables forwarding logs to New Relic Logging. Make sure you run `newrelic-lambda subscriptions install --function ... --filter-pattern ""` afterwards. |
173
176
  | `--memory-size` or `-m` | No | Memory size (in MiB) for the New Relic log ingestion function. |
177
+ | `--enable-license-key-secret` | No | Securely manages and store your New Relic license key in `AWS Secrets Manager` |
174
178
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. |
175
179
  | `--timeout` or `-t` | No | Timeout (in seconds) for the New Relic log ingestion function. |
176
180
  | `--role-name` | No | Role name for the ingestion function. If you prefer to create and manage an IAM role for the function to assume out of band, do so and specify that role's name here. This avoids needing CAPABILITY_IAM. |
@@ -198,11 +202,16 @@ newrelic-lambda layers install \
198
202
  | `--layer-arn` or `-l` | No | Specify a specific layer version ARN to use. This is auto detected by default. |
199
203
  | `--upgrade` or `-u` | No | Permit upgrade to the latest layer version for this region and runtime. |
200
204
  | `--disable-extension` | No | Disable the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). |
201
- | `--enable-extension-function-logs` | No | Enable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
205
+ | `--enable-extension-function-logs` or `--send-function-logs` | No | Enable sending Lambda function logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
206
+ | `--disable-extension-function-logs` or `--disable-function-logs` | No | Disable sending Lambda function logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension).|
207
+ | `--send-extension-logs` | No | Enable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension). Disabled by default. |
208
+ | `--disable-extension-logs` | No | Disable forwarding logs via the [New Relic Lambda Extension](https://github.com/newrelic/newrelic-lambda-extension).|
202
209
  | `--aws-profile` or `-p` | No | The AWS profile to use for this command. Can also use `AWS_PROFILE`. Will also check `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables if not using AWS CLI. |
203
210
  | `--aws-region` or `-r` | No | The AWS region this function is located. Can use `AWS_DEFAULT_REGION` environment variable. Defaults to AWS session region. |
204
211
  | `--nr-api-key` or `-k` | No | Your [New Relic User API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key). Can also use the `NEW_RELIC_API_KEY` environment variable. Only used if `--enable-extension` is set and there is no New Relic license key in AWS Secrets Manager. |
205
212
  | `--nr-region` | No | The New Relic region to use for the integration. Can use the `NEW_RELIC_REGION` environment variable. Can be either `eu` or `us`. Defaults to `us`. Only used if `--enable-extension` is set and there is no New Relic license key in AWS Secrets Manager. |
213
+ | `--nr-env-delimite` | No | Set `NR_ENV_DELIMITER` environment variable for your Lambda Function |
214
+ | `--nr-tags` | No | Set `NR_TAGS` environment variable for your Lambda Function |
206
215
  | `--java_handler_method` or `-j` | No | For java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest `--java_handler_method handleStreamsRequest`. |
207
216
  | `--esm` | No | For Node.js functions using ES Modules (ESM), enable the specific ESM wrapper during installation (e.g., using the --esm flag). This sets the Lambda handler to `/opt/nodejs/node_modules/newrelic-esm-lambda-wrapper/index.handler`. |
208
217
 
@@ -6,7 +6,7 @@ README = open(os.path.join(os.path.dirname(__file__), "README.md"), "r").read()
6
6
 
7
7
  setup(
8
8
  name="newrelic-lambda-cli",
9
- version="0.9.9",
9
+ version="0.9.11",
10
10
  python_requires=">=3.3",
11
11
  description="A CLI to install the New Relic AWS Lambda integration and layers.",
12
12
  long_description=README,
@@ -1,4 +1,5 @@
1
1
  import boto3
2
+ import click
2
3
  from click import UsageError
3
4
  from moto import mock_aws
4
5
  import pytest
@@ -49,13 +50,13 @@ def test_add_new_relic(aws_credentials, mock_function_config):
49
50
  )
50
51
  assert (
51
52
  update_kwargs["Environment"]["Variables"]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED"]
52
- == "true"
53
+ == "false"
53
54
  )
54
55
  assert (
55
56
  update_kwargs["Environment"]["Variables"][
56
57
  "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
57
58
  ]
58
- == "true"
59
+ == "false"
59
60
  )
60
61
 
61
62
  config = mock_function_config("not.a.runtime")
@@ -316,7 +317,6 @@ def test_install_apm(aws_credentials, mock_function_config):
316
317
  "EXISTING_ENV_VAR": "Hello World",
317
318
  "NEW_RELIC_ACCOUNT_ID": "12345",
318
319
  "NEW_RELIC_LAMBDA_HANDLER": "original_handler",
319
- "NEW_RELIC_LAMBDA_EXTENSION_ENABLED": "false",
320
320
  "NEW_RELIC_APM_LAMBDA_MODE": "True",
321
321
  }
322
322
  },
@@ -378,13 +378,13 @@ def test_add_new_relic_dotnet(aws_credentials, mock_function_config):
378
378
  update_kwargs["Environment"]["Variables"][
379
379
  "NEW_RELIC_LAMBDA_EXTENSION_ENABLED"
380
380
  ]
381
- == "true"
381
+ == "false"
382
382
  )
383
383
  assert (
384
384
  update_kwargs["Environment"]["Variables"][
385
385
  "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
386
386
  ]
387
- == "true"
387
+ == "false"
388
388
  )
389
389
 
390
390
  # .NET specific environment variables
@@ -462,7 +462,7 @@ def test_add_new_relic_nodejs(aws_credentials, mock_function_config):
462
462
  update_kwargs_std["Environment"]["Variables"][
463
463
  "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
464
464
  ]
465
- == "true"
465
+ == "false"
466
466
  )
467
467
 
468
468
  # --- Scenario 2: ESM Node.js Handler (ESM enabled) ---
@@ -514,7 +514,7 @@ def test_add_new_relic_nodejs(aws_credentials, mock_function_config):
514
514
  update_kwargs_esm["Environment"]["Variables"][
515
515
  "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
516
516
  ]
517
- == "true"
517
+ == "false"
518
518
  )
519
519
 
520
520
 
@@ -621,7 +621,13 @@ def test_install_failure(aws_credentials, mock_function_config):
621
621
  mock_client.get_function.return_value = config
622
622
  with pytest.raises(UsageError):
623
623
  install(
624
- layer_install(nr_account_id=9876543, session=mock_session), "foobarbaz"
624
+ layer_install(
625
+ nr_account_id=9876543,
626
+ session=mock_session,
627
+ nr_api_key=None,
628
+ nr_ingest_key=None,
629
+ ),
630
+ "foobarbaz",
625
631
  )
626
632
 
627
633
 
@@ -639,7 +645,13 @@ def test_install(aws_credentials, mock_function_config):
639
645
  mock_client.get_function.return_value = config
640
646
  with pytest.raises(UsageError):
641
647
  install(
642
- layer_install(nr_account_id=9876543, session=mock_session), "foobarbaz"
648
+ layer_install(
649
+ nr_account_id=9876543,
650
+ session=mock_session,
651
+ nr_api_key=None,
652
+ nr_ingest_key=None,
653
+ ),
654
+ "foobarbaz",
643
655
  )
644
656
 
645
657
  mock_client = mock_session.client.return_value
@@ -681,7 +693,6 @@ def test_install(aws_credentials, mock_function_config):
681
693
  "EXISTING_ENV_VAR": "Hello World",
682
694
  "NEW_RELIC_ACCOUNT_ID": "12345",
683
695
  "NEW_RELIC_LAMBDA_HANDLER": "original_handler",
684
- "NEW_RELIC_LAMBDA_EXTENSION_ENABLED": "false",
685
696
  }
686
697
  },
687
698
  Layers=ANY,
@@ -781,3 +792,643 @@ def test_install_success_message_new_layer(aws_credentials, mock_function_config
781
792
  "Successfully installed Layer ARN %s for the function: %s"
782
793
  % (new_layer_arn, function_arn)
783
794
  )
795
+
796
+
797
+ @mock_aws
798
+ def test_extension_logs_flags(aws_credentials, mock_function_config):
799
+ """Test that --send-extension-logs and --disable-extension-logs flags work correctly"""
800
+ session = boto3.Session(region_name="us-east-1")
801
+ nr_account_id = 12345
802
+
803
+ # Test 1: Fresh install with default settings - logs should be disabled by default
804
+ config = mock_function_config("python3.12")
805
+ update_kwargs = _add_new_relic(
806
+ layer_install(
807
+ session=session,
808
+ aws_region="us-east-1",
809
+ nr_account_id=nr_account_id,
810
+ enable_extension=True,
811
+ ),
812
+ config,
813
+ nr_license_key=None,
814
+ )
815
+
816
+ assert (
817
+ update_kwargs["Environment"]["Variables"][
818
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
819
+ ]
820
+ == "false"
821
+ )
822
+
823
+ # Test 2: Fresh install with --send-extension-logs
824
+ config = mock_function_config("python3.12")
825
+ update_kwargs = _add_new_relic(
826
+ layer_install(
827
+ session=session,
828
+ aws_region="us-east-1",
829
+ nr_account_id=nr_account_id,
830
+ enable_extension=True,
831
+ send_extension_logs=True,
832
+ ),
833
+ config,
834
+ nr_license_key=None,
835
+ )
836
+
837
+ assert (
838
+ update_kwargs["Environment"]["Variables"][
839
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
840
+ ]
841
+ == "false"
842
+ )
843
+
844
+ # Test 3: Upgrade with --send-extension-logs - should set to true
845
+ config = mock_function_config("python3.12")
846
+ config["Configuration"]["Environment"]["Variables"][
847
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
848
+ ] = "false"
849
+
850
+ update_kwargs = _add_new_relic(
851
+ layer_install(
852
+ session=session,
853
+ aws_region="us-east-1",
854
+ nr_account_id=nr_account_id,
855
+ enable_extension=True,
856
+ send_extension_logs=True,
857
+ upgrade=True,
858
+ ),
859
+ config,
860
+ nr_license_key=None,
861
+ )
862
+
863
+ assert (
864
+ update_kwargs["Environment"]["Variables"][
865
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
866
+ ]
867
+ == "true"
868
+ )
869
+
870
+ # Test 4: Upgrade with --disable-extension-logs - should set to false
871
+ config = mock_function_config("python3.12")
872
+ config["Configuration"]["Environment"]["Variables"][
873
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
874
+ ] = "true"
875
+
876
+ update_kwargs = _add_new_relic(
877
+ layer_install(
878
+ session=session,
879
+ aws_region="us-east-1",
880
+ nr_account_id=nr_account_id,
881
+ enable_extension=True,
882
+ disable_extension_logs=True,
883
+ upgrade=True,
884
+ ),
885
+ config,
886
+ nr_license_key=None,
887
+ )
888
+
889
+ assert (
890
+ update_kwargs["Environment"]["Variables"][
891
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
892
+ ]
893
+ == "false"
894
+ )
895
+
896
+ # Test 5: Upgrade without flags - should preserve existing value
897
+ config = mock_function_config("python3.12")
898
+ config["Configuration"]["Environment"]["Variables"][
899
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
900
+ ] = "true"
901
+
902
+ update_kwargs = _add_new_relic(
903
+ layer_install(
904
+ session=session,
905
+ aws_region="us-east-1",
906
+ nr_account_id=nr_account_id,
907
+ enable_extension=True,
908
+ upgrade=True,
909
+ ),
910
+ config,
911
+ nr_license_key=None,
912
+ )
913
+
914
+ assert (
915
+ update_kwargs["Environment"]["Variables"][
916
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
917
+ ]
918
+ == "true"
919
+ )
920
+
921
+
922
+ @mock_aws
923
+ def test_function_logs_flags(aws_credentials, mock_function_config):
924
+ """Test that --send-function-logs and --disable-function-logs flags work correctly"""
925
+ session = boto3.Session(region_name="us-east-1")
926
+ nr_account_id = 12345
927
+
928
+ # Test 1: Fresh install with default settings - logs should be disabled by default
929
+ config = mock_function_config("python3.12")
930
+ update_kwargs = _add_new_relic(
931
+ layer_install(
932
+ session=session,
933
+ aws_region="us-east-1",
934
+ nr_account_id=nr_account_id,
935
+ enable_extension=True,
936
+ ),
937
+ config,
938
+ nr_license_key=None,
939
+ )
940
+
941
+ assert (
942
+ update_kwargs["Environment"]["Variables"][
943
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
944
+ ]
945
+ == "false"
946
+ )
947
+
948
+ # Test 2: Fresh install with --send-function-logs - should still be false
949
+ config = mock_function_config("python3.12")
950
+ update_kwargs = _add_new_relic(
951
+ layer_install(
952
+ session=session,
953
+ aws_region="us-east-1",
954
+ nr_account_id=nr_account_id,
955
+ enable_extension=True,
956
+ send_function_logs=True,
957
+ ),
958
+ config,
959
+ nr_license_key=None,
960
+ )
961
+
962
+ assert (
963
+ update_kwargs["Environment"]["Variables"][
964
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
965
+ ]
966
+ == "false"
967
+ )
968
+
969
+ # Test 3: Upgrade with --send-function-logs - should set to true
970
+ config = mock_function_config("python3.12")
971
+ config["Configuration"]["Environment"]["Variables"][
972
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
973
+ ] = "false"
974
+
975
+ update_kwargs = _add_new_relic(
976
+ layer_install(
977
+ session=session,
978
+ aws_region="us-east-1",
979
+ nr_account_id=nr_account_id,
980
+ enable_extension=True,
981
+ send_function_logs=True,
982
+ upgrade=True,
983
+ ),
984
+ config,
985
+ nr_license_key=None,
986
+ )
987
+
988
+ assert (
989
+ update_kwargs["Environment"]["Variables"][
990
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
991
+ ]
992
+ == "true"
993
+ )
994
+
995
+ # Test 4: Upgrade with --disable-function-logs - should set to false
996
+ config = mock_function_config("python3.12")
997
+ config["Configuration"]["Environment"]["Variables"][
998
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
999
+ ] = "true"
1000
+
1001
+ update_kwargs = _add_new_relic(
1002
+ layer_install(
1003
+ session=session,
1004
+ aws_region="us-east-1",
1005
+ nr_account_id=nr_account_id,
1006
+ enable_extension=True,
1007
+ disable_function_logs=True,
1008
+ upgrade=True,
1009
+ ),
1010
+ config,
1011
+ nr_license_key=None,
1012
+ )
1013
+
1014
+ assert (
1015
+ update_kwargs["Environment"]["Variables"][
1016
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
1017
+ ]
1018
+ == "false"
1019
+ )
1020
+
1021
+ # Test 5: Upgrade without flags - should preserve existing value
1022
+ config = mock_function_config("python3.12")
1023
+ config["Configuration"]["Environment"]["Variables"][
1024
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
1025
+ ] = "true"
1026
+
1027
+ update_kwargs = _add_new_relic(
1028
+ layer_install(
1029
+ session=session,
1030
+ aws_region="us-east-1",
1031
+ nr_account_id=nr_account_id,
1032
+ enable_extension=True,
1033
+ upgrade=True,
1034
+ ),
1035
+ config,
1036
+ nr_license_key=None,
1037
+ )
1038
+
1039
+ assert (
1040
+ update_kwargs["Environment"]["Variables"][
1041
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
1042
+ ]
1043
+ == "true"
1044
+ )
1045
+
1046
+
1047
+ @mock_aws
1048
+ def test_independent_log_settings(aws_credentials, mock_function_config):
1049
+ """Test that function logs and extension logs are independent settings"""
1050
+ session = boto3.Session(region_name="us-east-1")
1051
+ nr_account_id = 12345
1052
+
1053
+ # Test: Upgrade with one flag should not affect the other setting
1054
+ config = mock_function_config("python3.12")
1055
+ config["Configuration"]["Environment"]["Variables"][
1056
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
1057
+ ] = "true"
1058
+ config["Configuration"]["Environment"]["Variables"][
1059
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
1060
+ ] = "true"
1061
+
1062
+ # Set only function logs to false
1063
+ update_kwargs = _add_new_relic(
1064
+ layer_install(
1065
+ session=session,
1066
+ aws_region="us-east-1",
1067
+ nr_account_id=nr_account_id,
1068
+ enable_extension=True,
1069
+ disable_function_logs=True,
1070
+ upgrade=True,
1071
+ ),
1072
+ config,
1073
+ nr_license_key=None,
1074
+ )
1075
+
1076
+ # Function logs should be set to false, extension logs should be preserved
1077
+ assert (
1078
+ update_kwargs["Environment"]["Variables"][
1079
+ "NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
1080
+ ]
1081
+ == "false"
1082
+ )
1083
+ assert (
1084
+ update_kwargs["Environment"]["Variables"][
1085
+ "NEW_RELIC_EXTENSION_SEND_EXTENSION_LOGS"
1086
+ ]
1087
+ == "true"
1088
+ )
1089
+
1090
+
1091
+ @mock_aws
1092
+ def test_add_new_relic_sets_nr_tags(aws_credentials, mock_function_config):
1093
+ session = boto3.Session(region_name="us-east-1")
1094
+ config = mock_function_config("python3.12")
1095
+ tags_value = "foo:bar;baz:qux"
1096
+
1097
+ update_kwargs = _add_new_relic(
1098
+ layer_install(
1099
+ session=session,
1100
+ aws_region="us-east-1",
1101
+ nr_account_id=12345,
1102
+ enable_extension=True,
1103
+ enable_extension_function_logs=True,
1104
+ nr_tags=tags_value,
1105
+ ),
1106
+ config,
1107
+ nr_license_key=None,
1108
+ )
1109
+
1110
+ assert update_kwargs["Environment"]["Variables"]["NR_TAGS"] == tags_value
1111
+
1112
+
1113
+ @mock_aws
1114
+ def test_add_new_relic_sets_nr_env_delimiter(aws_credentials, mock_function_config):
1115
+ session = boto3.Session(region_name="us-east-1")
1116
+ config = mock_function_config("python3.12")
1117
+ delimiter_value = "|"
1118
+
1119
+ update_kwargs = _add_new_relic(
1120
+ layer_install(
1121
+ session=session,
1122
+ aws_region="us-east-1",
1123
+ nr_account_id=12345,
1124
+ enable_extension=True,
1125
+ enable_extension_function_logs=True,
1126
+ nr_env_delimiter=delimiter_value,
1127
+ ),
1128
+ config,
1129
+ nr_license_key=None,
1130
+ )
1131
+
1132
+ assert (
1133
+ update_kwargs["Environment"]["Variables"]["NR_ENV_DELIMITER"] == delimiter_value
1134
+ )
1135
+
1136
+
1137
+ @mock_aws
1138
+ def test_add_new_relic_sets_both_nr_tags_and_env_delimiter(
1139
+ aws_credentials, mock_function_config
1140
+ ):
1141
+ session = boto3.Session(region_name="us-east-1")
1142
+ config = mock_function_config("python3.12")
1143
+ tags_value = "foo:bar|baz:qux"
1144
+ delimiter_value = "|"
1145
+
1146
+ update_kwargs = _add_new_relic(
1147
+ layer_install(
1148
+ session=session,
1149
+ aws_region="us-east-1",
1150
+ nr_account_id=12345,
1151
+ enable_extension=True,
1152
+ enable_extension_function_logs=True,
1153
+ nr_tags=tags_value,
1154
+ nr_env_delimiter=delimiter_value,
1155
+ ),
1156
+ config,
1157
+ nr_license_key=None,
1158
+ )
1159
+
1160
+ assert update_kwargs["Environment"]["Variables"]["NR_TAGS"] == tags_value
1161
+ assert (
1162
+ update_kwargs["Environment"]["Variables"]["NR_ENV_DELIMITER"] == delimiter_value
1163
+ )
1164
+
1165
+
1166
+ @mock_aws
1167
+ def test_add_new_relic_with_ingest_key(aws_credentials, mock_function_config):
1168
+ """Test _add_new_relic function with ingest key instead of API key"""
1169
+ session = boto3.Session(region_name="us-east-1")
1170
+
1171
+ config = mock_function_config("python3.12")
1172
+
1173
+ update_kwargs = _add_new_relic(
1174
+ layer_install(
1175
+ session=session,
1176
+ aws_region="us-east-1",
1177
+ nr_account_id=12345,
1178
+ enable_extension=True,
1179
+ nr_ingest_key="test-ingest-key-12345",
1180
+ ),
1181
+ config,
1182
+ nr_license_key=None,
1183
+ )
1184
+
1185
+ # Verify ingest key is used for NEW_RELIC_LICENSE_KEY
1186
+ assert (
1187
+ update_kwargs["Environment"]["Variables"]["NEW_RELIC_LICENSE_KEY"]
1188
+ == "test-ingest-key-12345"
1189
+ )
1190
+ assert (
1191
+ update_kwargs["Environment"]["Variables"]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED"]
1192
+ == "true"
1193
+ )
1194
+
1195
+
1196
+ @mock_aws
1197
+ def test_add_new_relic_without_license_key_or_ingest_key(
1198
+ aws_credentials, mock_function_config
1199
+ ):
1200
+ """Test _add_new_relic function when neither license key nor ingest key is provided"""
1201
+ session = boto3.Session(region_name="us-east-1")
1202
+
1203
+ config = mock_function_config("python3.12")
1204
+
1205
+ update_kwargs = _add_new_relic(
1206
+ layer_install(
1207
+ session=session,
1208
+ aws_region="us-east-1",
1209
+ nr_account_id=12345,
1210
+ enable_extension=True,
1211
+ ),
1212
+ config,
1213
+ nr_license_key=None,
1214
+ )
1215
+
1216
+ # When no license key or ingest key is provided, extension should be disabled
1217
+ assert (
1218
+ update_kwargs["Environment"]["Variables"]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED"]
1219
+ == "false"
1220
+ )
1221
+ assert "NEW_RELIC_LICENSE_KEY" not in update_kwargs["Environment"]["Variables"]
1222
+
1223
+
1224
+ @mock_aws
1225
+ def test_add_new_relic_staging_region(aws_credentials, mock_function_config):
1226
+ """Test _add_new_relic function with staging region"""
1227
+ session = boto3.Session(region_name="us-east-1")
1228
+
1229
+ config = mock_function_config("python3.12")
1230
+
1231
+ update_kwargs = _add_new_relic(
1232
+ layer_install(
1233
+ session=session,
1234
+ aws_region="us-east-1",
1235
+ nr_account_id=12345,
1236
+ enable_extension=True,
1237
+ nr_region="staging",
1238
+ nr_ingest_key="test-ingest-key",
1239
+ ),
1240
+ config,
1241
+ nr_license_key=None,
1242
+ )
1243
+
1244
+ # Verify staging endpoints are set
1245
+ assert (
1246
+ update_kwargs["Environment"]["Variables"]["NEW_RELIC_TELEMETRY_ENDPOINT"]
1247
+ == "https://staging-cloud-collector.newrelic.com/aws/lambda/v1"
1248
+ )
1249
+ assert (
1250
+ update_kwargs["Environment"]["Variables"]["NEW_RELIC_LOG_ENDPOINT"]
1251
+ == "https://staging-log-api.newrelic.com/log/v1"
1252
+ )
1253
+
1254
+
1255
+ def test_install_with_both_api_key_and_ingest_key(
1256
+ aws_credentials, mock_function_config
1257
+ ):
1258
+ """Test install function fails when both API key and ingest key are provided"""
1259
+ mock_session = MagicMock()
1260
+ mock_session.region_name = "us-east-1"
1261
+
1262
+ with pytest.raises(
1263
+ UsageError,
1264
+ match="Please provide either the --nr-api-key or the --nr-ingest-key flag, but not both",
1265
+ ):
1266
+ install(
1267
+ layer_install(
1268
+ session=mock_session,
1269
+ nr_account_id=12345,
1270
+ nr_api_key="test-api-key",
1271
+ nr_ingest_key="test-ingest-key",
1272
+ ),
1273
+ "test-function",
1274
+ )
1275
+
1276
+
1277
+ def test_install_with_ingest_key_success(aws_credentials, mock_function_config):
1278
+ """Test successful install with ingest key"""
1279
+ mock_session = MagicMock()
1280
+ mock_session.region_name = "us-east-1"
1281
+ mock_client = mock_session.client.return_value
1282
+
1283
+ with patch(
1284
+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1285
+ ) as mock_get_license_key_outputs, patch(
1286
+ "newrelic_lambda_cli.layers.get_function"
1287
+ ) as mock_get_function, patch(
1288
+ "newrelic_lambda_cli.layers._add_new_relic"
1289
+ ) as mock_add_new_relic:
1290
+
1291
+ # Set up policy_arn so GraphQL validation is skipped
1292
+ mock_get_license_key_outputs.return_value = (None, "12345", "test-policy-arn")
1293
+ mock_get_function.return_value = mock_function_config("python3.12")
1294
+ mock_add_new_relic.return_value = {
1295
+ "FunctionName": "test-function",
1296
+ "Environment": {"Variables": {"NEW_RELIC_LICENSE_KEY": "test-ingest-key"}},
1297
+ "Layers": ["test-layer"],
1298
+ }
1299
+ mock_client.update_function_configuration.return_value = {
1300
+ "Configuration": {
1301
+ "Layers": [{"Arn": "existing-layer"}],
1302
+ "FunctionArn": "test-function",
1303
+ }
1304
+ }
1305
+
1306
+ result = install(
1307
+ layer_install(
1308
+ session=mock_session,
1309
+ nr_account_id=12345,
1310
+ nr_ingest_key="test-ingest-key",
1311
+ enable_extension=False,
1312
+ ),
1313
+ "test-function",
1314
+ )
1315
+
1316
+ assert result is True
1317
+ mock_client.update_function_configuration.assert_called_once()
1318
+
1319
+
1320
+ @mock_aws
1321
+ def test_install_with_apm_and_verbose(aws_credentials, mock_function_config):
1322
+ """Test install with APM enabled and verbose output to cover success message paths"""
1323
+ mock_session = MagicMock()
1324
+ mock_session.region_name = "us-east-1"
1325
+ mock_client = mock_session.client.return_value
1326
+
1327
+ with patch(
1328
+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1329
+ ) as mock_get_license_key_outputs, patch(
1330
+ "newrelic_lambda_cli.layers.get_function"
1331
+ ) as mock_get_function, patch(
1332
+ "newrelic_lambda_cli.layers._add_new_relic"
1333
+ ) as mock_add_new_relic:
1334
+
1335
+ mock_get_license_key_outputs.return_value = (None, "12345", "test-policy-arn")
1336
+ mock_get_function.return_value = mock_function_config("python3.12")
1337
+ mock_add_new_relic.return_value = {
1338
+ "FunctionName": "test-function",
1339
+ "Environment": {"Variables": {"NEW_RELIC_LICENSE_KEY": "test-key"}},
1340
+ "Layers": ["test-layer"],
1341
+ }
1342
+ mock_client.update_function_configuration.return_value = {
1343
+ "Configuration": {"Layers": [], "FunctionArn": "test-function"}
1344
+ }
1345
+ mock_client.tag_resource.return_value = {}
1346
+
1347
+ result = install(
1348
+ layer_install(
1349
+ session=mock_session,
1350
+ nr_account_id=12345,
1351
+ nr_api_key="test-api-key",
1352
+ nr_region="us",
1353
+ apm=True,
1354
+ verbose=True,
1355
+ enable_extension=False,
1356
+ ),
1357
+ "test-function",
1358
+ )
1359
+
1360
+ assert result is True
1361
+ mock_client.tag_resource.assert_called_once()
1362
+
1363
+
1364
+ @mock_aws
1365
+ def test_install_function_not_found(aws_credentials):
1366
+ """Test install function when function is not found"""
1367
+ mock_session = MagicMock()
1368
+ mock_session.region_name = "us-east-1"
1369
+
1370
+ with patch("newrelic_lambda_cli.layers.get_function") as mock_get_function:
1371
+ mock_get_function.return_value = None
1372
+
1373
+ result = install(
1374
+ layer_install(
1375
+ session=mock_session,
1376
+ nr_account_id=12345,
1377
+ nr_api_key="test-api-key",
1378
+ ),
1379
+ "nonexistent-function",
1380
+ )
1381
+
1382
+ assert result is False
1383
+
1384
+
1385
+ def test_install_secret_account_mismatch(aws_credentials):
1386
+ """Test install with managed secret account ID mismatch"""
1387
+ mock_session = MagicMock()
1388
+ mock_session.region_name = "us-east-1"
1389
+
1390
+ with patch(
1391
+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1392
+ ) as mock_get_license_key_outputs, patch(
1393
+ "newrelic_lambda_cli.layers.get_function"
1394
+ ) as mock_get_function:
1395
+
1396
+ # Different account ID in existing secret
1397
+ mock_get_license_key_outputs.return_value = (None, "99999", "test-policy-arn")
1398
+ mock_get_function.return_value = {"Configuration": {"FunctionArn": "test"}}
1399
+
1400
+ with pytest.raises(UsageError, match="A managed secret already exists"):
1401
+ install(
1402
+ layer_install(
1403
+ session=mock_session,
1404
+ nr_account_id=12345, # Different from secret account ID
1405
+ nr_ingest_key="test-ingest-key",
1406
+ ),
1407
+ "test-function",
1408
+ )
1409
+
1410
+
1411
+ def test_install_extension_without_secret_or_api_key(aws_credentials):
1412
+ """Test install with extension enabled but no secret or API key"""
1413
+ mock_session = MagicMock()
1414
+ mock_session.region_name = "us-east-1"
1415
+
1416
+ with patch(
1417
+ "newrelic_lambda_cli.layers._get_license_key_outputs"
1418
+ ) as mock_get_license_key_outputs, patch(
1419
+ "newrelic_lambda_cli.layers.get_function"
1420
+ ) as mock_get_function:
1421
+
1422
+ mock_get_license_key_outputs.return_value = (None, None, None) # No secret
1423
+ mock_get_function.return_value = {"Configuration": {"FunctionArn": "test"}}
1424
+
1425
+ with pytest.raises(UsageError, match="In order to use `--enable-extension`"):
1426
+ install(
1427
+ layer_install(
1428
+ session=mock_session,
1429
+ nr_account_id=12345,
1430
+ enable_extension=True,
1431
+ nr_ingest_key="test-ingest-key",
1432
+ ),
1433
+ "test-function",
1434
+ )