DEV Community

chrishart0 for Signet Seal

Posted on

6 1

Enable Lambda Insights Using Python AWS CDK

Code for enabling Lambda Insights with the Python CDK

# Define the layer, make sure you use the right layer for your region and the pick the most up to date layer https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-extension-versions.html

layerArn='arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:14'
insight_layer = _lambda.LayerVersion.from_layer_version_arn(self,'lambda_insights_layer',layerArn)

#Add the layer to the function as shown below
_lambda.Function(
    self, 'my_function',
    runtime=_lambda.Runtime.PYTHON_3_8,
    handler='my_function.handler',
    code=_lambda.Code.from_asset(
        path = 'lambda'
    ),
    layers=[insight_layer]
)

# Optional: Add the managed policy 
If using the `AWSLambdaBasicExecutionRole`, which CDK uses by default when creating a Lambda function, there is no need to do this. Otherwise, add the `CloudWatchLambdaInsightsExecutionRolePolicy` managed policy to the function.

Enter fullscreen mode Exit fullscreen mode

Note: make sure to pick the most up to date and correct region ARN for the Lambda Insights Extension layer. Reference these docs here for ARNs for all regions and version

Here are the AWS docs on how to enable Lambda Insights for the Typescript CDK.

More CDK or AWS Serverless Questions?

Feel free to leave a comment here or hit us up on LinkedIn.

Want to learn more about how SignetSeal can help make your chats more secure? Read more about us on our website SignetSeal.com

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay