Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

Community Plus header

newrelic-lambda-cli Build StatusCoverage

A CLI to install the New Relic AWS Lambda integration and layers.

Table of Contents

Features

  • Installs the New Relic AWS Lambda integration onto your AWS account
  • Installs and configures a New Relic AWS Lambda layer onto your AWS Lambda functions
  • Automatically selects the correct New Relic layer for your function's runtime and region
  • Wraps your AWS Lambda functions without requiring a code change
  • Supports Go, Java, .NET, Node.js and Python AWS Lambda runtimes
  • Easily uninstall the AWS Lambda layer with a single command

Runtimes Supported

  • dotnetcore3.1
  • java8.al2
  • java11
  • nodejs12.x
  • nodejs14.x
  • nodejs16.x
  • provided
  • provided.al2
  • python3.6
  • python3.7
  • python3.8
  • python3.9

Note: Automatic handler wrapping is only supported for Node.js and Python. For other runtimes, manual function wrapping is required using the runtime specific New Relic agent.

Requirements

Recommendations

  • Install the AWS CLI and configure your environment with aws configure

Installation

pip3 install newrelic-lambda-cli

Or clone this repo and run:

python3 setup.py install

To update the CLI, run:

pip3 install --upgrade newrelic-lambda-cli

Usage

AWS Lambda Integration

Install Integration

In order to instrument your AWS Lambda functions using New Relic you must first install the New Relic AWS Lambda integration and the log ingestion function in the AWS region in which your Lambda functions are located. If you have Lambda functions located in multiple regions you can run the command multiple times specifying the AWS regions with --aws-region <your aws region here>. This command only needs to be run once per AWS region. By default this command will look for a default AWS profile configured via the AWS CLI.

newrelic-lambda integrations install \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for this integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable.
--linked-account-name or -nNoA label for the New Relic Linked Account. This is how this integration will appear in New Relic. Defaults to "New Relic Lambda Integration - ".
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. This is disabled by default. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function. Default to 128MB.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function. Defaults to 30 seconds.
--role-nameNoRole 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.
--integration-arnNoSpecify an existing AWS IAM role to use for the New Relic Lambda integration instead of creating one.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--aws-role-policyNoSpecify an alternative IAM role policy ARN for this integration.
--disable-license-key-secretNoDon't create a managed secret for your account's New Relic License Key
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

Uninstall Integration

newrelic-lambda integrations uninstall
OptionRequired?Description
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--force or -fNoForces uninstall non-interactively
--nr-account-id or -aNoThe New Relic Account ID for the integration. Only required if also uninstalling the New Relic AWS Lambda integration. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.

Update Integration

Updates the New Relic log ingestion function to the latest version. Existing ingestion function parameters will retain their values, unless you specify different values on the command line. By default, installs the license key secret, if it is missing.

newrelic-lambda integrations update \
--nr-account-id <account id> \
--nr-api-key <api key>
OptionRequired?Description
--nr-account-id or -aYesThe New Relic Account ID for the integration. Only required if changing the account to which the logs are sent. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--nr-api-key or -kYesYour New Relic User API Key. Can also use the NEW_RELIC_API_KEY environment variable. Only required if changing the account to which the logs are sent.
--disable-logs or -dNoDisables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... afterwards.
--enable-logs or -eNoEnables forwarding logs to New Relic Logging. Make sure you run newrelic-lambda subscriptions install --function ... --filter-pattern "" afterwards.
--memory-size or -mNoMemory size (in MiB) for the New Relic log ingestion function.
--nr-regionNoThe 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.
--timeout or -tNoTimeout (in seconds) for the New Relic log ingestion function.
--role-nameNoRole 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.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region for the integration. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--disable-license-key-secretNoDisable automatic creation of the license key secret on update. The secret is not created if it exists.
--tag <key> <value>NoSets tags on the CloudFormation Stacks this CLI creates. Can be used multiple times, example: --tag key1 value1 --tag key2 value2.

AWS Lambda Layers

Install Layer

newrelic-lambda layers install \
--function <name or arn> \
--nr-account-id <new relic account id>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--nr-account-id or -aYesThe New Relic Account ID this function should use. Can also use the NEW_RELIC_ACCOUNT_ID environment variable.
--exclude or -eNoA function name to exclude while installing layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to use. This is auto detected by default.
--upgrade or -uNoPermit upgrade to the latest layer version for this region and runtime.
--disable-extensionNoDisable the New Relic Lambda Extension.
--enable-extension-function-logsNoEnable forwarding logs via the New Relic Lambda Extension. Disabled by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.
--nr-api-key or -kNoYour New Relic 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.
--nr-regionNoThe 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.
--java_handler_method or -jNoFor java runtimes only to specify an aws implementation method. Defaults to RequestHandler. Optional inputs are: handleRequest, handleStreamsRequest --java_handler_method handleStreamsRequest.

Uninstall Layer

newrelic-lambda layers uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a layer. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling layers. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--layer-arn or -lNoSpecify a specific layer version ARN to remove. This is auto detected by default.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

AWS Lambda Functions

List Functions

newrelic-lambda functions list

List functions with layer installed:

newrelic-lambda functions list --filter installed
OptionRequired?Description
--filter or -fNoFilter to be applied to list of functions. Options are all, installed and not-installed. Defaults to all.
--output or -oNoSpecify the desired output format. Supports table and text. Defaults to table.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region to use for this command. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

NewRelic Log Subscription

Install Log Subscription

newrelic-lambda subscriptions install --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to add a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while installing subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--filter-patternNoSpecify a custom log subscription filter pattern. To collect all logs use --filter-pattern "".
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Uninstall Log Subscription

newrelic-lambda subscriptions uninstall --function <name or arn>
OptionRequired?Description
--function or -fYesThe AWS Lambda function name or ARN in which to remove a log subscription. Can provide multiple --function arguments. Will also accept all, installed and not-installed similar to newrelic-lambda functions list.
--exclude or -eNoA function name to exclude while uninstalling subscriptions. Can provide multiple --exclude arguments. Only checked when all, installed and not-installed are used. See newrelic-lambda functions list for function names.
--aws-profile or -pNoThe 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.
--aws-region or -rNoThe AWS region this function is located. Can use AWS_DEFAULT_REGION environment variable. Defaults to AWS session region.

Docker

Now, you can run newrelic-lambda-cli as a container.

docker build -t newrelic-lambda-cli .
docker run -e AWS_PROFILE=your_profile -v $HOME/.aws:/home/newrelic-lambda-cli/.aws newrelic-lambda-cli functions list

Contributing

We welcome code contributions (in the form of pull requests) from our user community. Before submitting a pull request please review these guidelines.

Following these helps us efficiently review and incorporate your contribution and avoid breaking your code with future changes to the agent.

Code style

We use the black code formatter.

pip install black

We recommend using it with pre-commit:

pip install pre-commit
pre-commit install

Using these together will auto format your git commits.

Running Tests

python setup.py test

Troubleshooting

Upgrade the CLI: A good first step, as we push updates frequently.

pip3 install --upgrade newrelic-lambda-cli

UnrecognizedClientException:

(UnrecognizedClientException) when calling the GetFunction operation: The security token included in the request is invalid.

If you see this error, it means that specifying the region is necessary, and you need to supply the --aws-region flag to your command.

Unable to locate credentials:

Function: None, Region: None, Error: Failed to set up lambda integration: 'Unable to locate credentials. You can configure credentials by running "aws configure".'

  1. The AWS profile may not be properly configured; review documentation to Configure your AWS Profile (make sure the default region is set!).
  2. If there are multiple AWS profiles and the correct one is not specified, you can run export AWS_DEFAULT_PROFILE=MY_OTHER_PROFILE to set the environment variable to the proper profile.

SimulatePrincipalPolicy:

botocore.errorfactory.InvalidInputException: An error occurred (InvalidInput) when calling the SimulatePrincipalPolicy operation: Invalid Entity Arn: arn:aws:sts::123456789012:assumed-role/u-admin/botocore-session-0987654321 does not clearly define entity type and name.

Some AWS accounts can have permission to operate on resources without having access to SimulatePrincipalPolicy. If this is the case, supply the --no-aws-permissions-check flag to your command.

Error adding new region to integration:

Linking New Relic account to AWS account Traceback (most recent call last): ... File "/Users/USER/PYTHONPATH/lib/python3.8/site-packages/newrelic_lambda_cli/gql.py", line 131, in link_account return res["cloudLinkAccount"]["linkedAccounts"][0] IndexError: list index out of range

This error can happen if you have an existing AWS integration, and are running newrelic-lambda integrations install with a different --linked-account-name (for instance, to add a new region to the integration). The linked account name can be whatever you want it to be, but needs to be consistent with the previously linked AWS account.

AWS Secrets Manager Secret Name Conflict This CLI manages a AWS Secrets Manager secret with the name NEW_RELIC_LICENSE_KEY. If you run into a CloudFormation error reporting that this secret already exists, make sure that you delete any existing secrets and try again. Keep in mind, by default in the AWS console when you delete a secret from AWS Secrets Manager that it will not delete the secret permanently for several days. You will need to perform a "force delete without recovery" when deleting the secret to avoid this naming conflict.

About

A CLI to install the New Relic AWS Lambda integration and layers.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages