Skip to content

Commit

Permalink
Add example for CDK Lambda instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudharysaket committed Oct 21, 2024
1 parent c09cbd2 commit 1cc8956
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ New Relic offers several methods to instrument your AWS Lambda functions for com
* **Command Line Interface (CLI)**: Use the AWS CLI to quickly add the New Relic layer to your Lambda functions.
* **Serverless Framework**: Seamlessly integrate New Relic instrumentation into your serverless deployments.
* **CloudFormation/SAM**: Include the New Relic layer in your infrastructure-as-code templates.
* **AWS CDK**: Add New Relic Lambda layer in your CDK code alongside other infrastructure resources.
* **Terraform**: Easily manage New Relic instrumentation alongside your other infrastructure resources.
* **Manual Instrumentation**: Directly add the New Relic layer through the AWS Lambda console for more granular control.

Expand Down Expand Up @@ -137,6 +138,46 @@ Depending on your needs, you can choose to either bypass the extension and only
```
</Collapser>

<Collapser
id="cdk"
title="AWS CDK"
>
The AWS Cloud Development Kit (AWS CDK) is a framework for defining cloud resources in code and provisioning it through AWS CloudFormation.

Below is an example of a basic CDK app that deploys a New Relic instrumented Node.js Lambda function:
```ts
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
export class NewRelicExampleCdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Add latest New Relic Lambda layer ARN from https://layers.newrelic-external.com
const NewReliclayerArn = 'arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS20X:39';
const myFunction = new lambda.Function(this, "NewRelicExampleLambda", {
runtime: lambda.Runtime.NODEJS_20_X,
// Update functions handler to point to the New Relic Lambda wrapper
handler: "newrelic-lambda-wrapper.handler",
code: lambda.Code.fromInline(`
exports.handler = async function(event) {
return {
statusCode: 200,
body: JSON.stringify('Hello World!'),
};
};
`),
layers: [lambda.LayerVersion.fromLayerVersionArn(this, 'NewRelicLayer', NewReliclayerArn)],
environment: {
// Set the NEW_RELIC_LAMBDA_HANDLER environment variable to the path to your initial handler.
NEW_RELIC_LAMBDA_HANDLER: 'index.handler',
},
});
}
}
```
</Collapser>
<Collapser
id="terraform"
title="Terraform"
Expand Down

0 comments on commit 1cc8956

Please sign in to comment.