diff --git a/src/content/docs/serverless-function-monitoring/aws-lambda-monitoring/instrument-lambda-function/instrument-your-own.mdx b/src/content/docs/serverless-function-monitoring/aws-lambda-monitoring/instrument-lambda-function/instrument-your-own.mdx index 42ca4f8c2b3..f078017d3c9 100644 --- a/src/content/docs/serverless-function-monitoring/aws-lambda-monitoring/instrument-lambda-function/instrument-your-own.mdx +++ b/src/content/docs/serverless-function-monitoring/aws-lambda-monitoring/instrument-lambda-function/instrument-your-own.mdx @@ -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. @@ -137,6 +138,46 @@ Depending on your needs, you can choose to either bypass the extension and only ``` + + 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', + }, + }); + } + } + ``` + +