Skip to content

(lambda): Lambda insights functionality #12489

@flemjame-at-amazon

Description

@flemjame-at-amazon

❓ 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-lambdaRelated to AWS Lambdaeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.feature/enhancementA new API to make things easier or more intuitive. A catch-all for general feature requests.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions