-
Notifications
You must be signed in to change notification settings - Fork 4.4k
(lambda): Lambda insights functionality #12489
Description
❓ General Issue
Lambda insights was released and the process for enabling requires writing the following code:
const layerArn = `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:12`;
const layer = lambda.LayerVersion.fromLayerVersionArn(this, 'LayerFromArn', layerArn);
const lambdaFunction = new lambda.Function(this, 'Function', {
...otherProps,
layers: [layer]
});
lambdaFunction.role?.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName('CloudWatchLambdaInsightsExecutionRolePolicy'))The Question
I'd like this to be natively integrated with Lambda functions, and want feedback on an approach to do so. Here's what I'm thinking now:
const lambdaFunction = new lambda.Function(this, 'Function', {
lambdaInsightsOptions? : {
layerArn?: string,
insightsVersion?: InsightsVersion
}
});
export class InsightsVersion {
public static readonly 1_0_89_0 = new InsightsVersion(...);
public static readonly 1_0_86_0 = new InsightsVersion(...);
private constructor(...);
}If lambdaInsightsOptions isn't provided, nothing happens. If it is provided, then the relevant managed policy and the appropriate lambda layer are applied to the function automatically.
Either layerArn or insightsVersion must be provided, but not both. This is what builds the lambda layer object. layerArn is an escape hatch, to allow for providing an arbitrary ARN in case a new version is released and a customer wants to use it immediately.
Insights versions are based on the provided versions: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-extension-versions.html
Environment
- CDK CLI Version: 1.84.0
- Language (Version): all