44
55This is a custom construct that will create AWS Lambda Layer with AWS Powertools for Python or NodeJS library. There are different
66ways how to create a layer and when working with CDK you need to install the library, create a zip file and wire it
7- correctly. With this construct you don't have to care about packaging and dependency management, create a construct
7+ correctly. With this construct you don't have to care about packaging and dependency management. Create a construct
88and add it to your function. The construct is an extension of the
99existing [ ` LayerVersion ` ] ( https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LayerVersion.html ) construct
1010from the CDK library, so you have access to all fields and methods.
1111
12+ > ⚠️ ** This construct uses docker to build and bundle the dependencies!**
13+
1214See the [ API] ( API.md ) for details.
1315
1416``` typescript
15- import { LambdaPowertoolsLayer } from ' cdk-aws=lambda-powertools-python-layer' ;
17+ import {LambdaPowertoolsLayer } from ' cdk-aws-lambda-powertools-layer' ;
18+ import {RuntimeFamily } from " aws-cdk-lib/aws-lambda" ;
1619
17- const powertoolsLayer = new LambdaPowertoolsLayer (this , ' TestLayer' );
20+ const powertoolsLayerPython = new LambdaPowertoolsLayer (this , ' TestLayer' , {runtimeFamily: RuntimeFamily .PYTHON });
21+ const powertoolsLayerNodeJS = new LambdaPowertoolsLayer (this , ' TestLayer' , {runtimeFamily: RuntimeFamily .NODEJS });
1822```
1923
2024Python
@@ -45,7 +49,7 @@ pip install cdk-aws-lambda-powertools-layer
4549
4650### Python
4751
48- A single line will create a layer with powertools for python:
52+ A single line will create a layer with powertools for python. For NodeJS you need to specifically set the ` runtimeFamily: Runtime.NODEJS ` property.
4953
5054``` python
5155from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer
@@ -61,7 +65,6 @@ from aws_cdk import aws_lambda
6165aws_lambda.Function(self , ' LambdaFunction' ,
6266 code = aws_lambda.Code.from_asset(' function' ),
6367 handler = ' app.handler' ,
64- runtime = aws_lambda.Runtime.PYTHON_3_9 ,
6568 layers = [powertoolsLayer])
6669```
6770
@@ -99,7 +102,6 @@ class LayerTestStack(Stack):
99102 aws_lambda.Function(self , ' LambdaFunction' ,
100103 code = aws_lambda.Code.from_asset(' function' ),
101104 handler = ' app.handler' ,
102- runtime = aws_lambda.Runtime.PYTHON_3_9 ,
103105 layers = [powertoolsLayer])
104106
105107```
@@ -127,7 +129,6 @@ export class CdkPowertoolsExampleStack extends Stack {
127129 new Function (this , ' LambdaFunction' , {
128130 code: Code .fromAsset (path .join (' ./function' )),
129131 handler: ' app.handler' ,
130- runtime: Runtime .PYTHON_3_9 ,
131132 layers: [powertoolsLayer ],
132133 });
133134 }
0 commit comments