Instrument Lambda Functions

Instrumenting AWS Lambda Functions

Now that we have linked your AWS and New Relic accounts, let’s install the New Relic Lambda layer for each of the AWS Lambda functions we wish to monitor in our AWS example application.

First, let’s export an environment variable containing our New Relic account id to make it easier to instrument each of our Lambda functions:


Next, we need to determine the names of the functions we wish to instrument:

newrelic-lambda functions list


Using the names of the functions retured by the command above, copy the commands listed below into CloudShell (Replacing –function arguments with their actual names) to instrument your Lambda functions:

newrelic-lambda layers install --nr-account-id $NR_ACCOUNT_ID --function PRODUCER_FUNCTION_NAME  --upgrade --enable-extension-function-logs
newrelic-lambda layers install --nr-account-id $NR_ACCOUNT_ID --function CONSUMER_FUNCTION_NAME  --upgrade --enable-extension-function-logs

The –upgrade– flag ensures all future layer versions of your Lambda function will include the New Relic Lambda extension by default.

The –enable-extension-function-logs flag configures the function to forward the CloudWatch Logs associated with the function to New Relic. This is not enabled by default when instrumenting functions due to the added cost, but as you will see later on in this workshop, provides great value in terms of observability.

To list your Lambda functions and verify that they are now instrumented, you can run the following command again:

newrelic-lambda functions list

Congratulations! You have successfully instrumented both Lambda functions used by the example application!