4
4
5
5
This is a custom construct that will create AWS Lambda Layer with AWS Powertools for Python or NodeJS library. There are different
6
6
ways 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
8
8
and add it to your function. The construct is an extension of the
9
9
existing [ ` LayerVersion ` ] ( https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LayerVersion.html ) construct
10
10
from the CDK library, so you have access to all fields and methods.
11
11
12
+ > ⚠️ ** This construct uses docker to build and bundle the dependencies!**
13
+
12
14
See the [ API] ( API.md ) for details.
13
15
14
16
``` 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" ;
16
19
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 });
18
22
```
19
23
20
24
Python
@@ -45,7 +49,7 @@ pip install cdk-aws-lambda-powertools-layer
45
49
46
50
### Python
47
51
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.
49
53
50
54
``` python
51
55
from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer
@@ -61,7 +65,6 @@ from aws_cdk import aws_lambda
61
65
aws_lambda.Function(self , ' LambdaFunction' ,
62
66
code = aws_lambda.Code.from_asset(' function' ),
63
67
handler = ' app.handler' ,
64
- runtime = aws_lambda.Runtime.PYTHON_3_9 ,
65
68
layers = [powertoolsLayer])
66
69
```
67
70
@@ -99,7 +102,6 @@ class LayerTestStack(Stack):
99
102
aws_lambda.Function(self , ' LambdaFunction' ,
100
103
code = aws_lambda.Code.from_asset(' function' ),
101
104
handler = ' app.handler' ,
102
- runtime = aws_lambda.Runtime.PYTHON_3_9 ,
103
105
layers = [powertoolsLayer])
104
106
105
107
```
@@ -127,7 +129,6 @@ export class CdkPowertoolsExampleStack extends Stack {
127
129
new Function (this , ' LambdaFunction' , {
128
130
code: Code .fromAsset (path .join (' ./function' )),
129
131
handler: ' app.handler' ,
130
- runtime: Runtime .PYTHON_3_9 ,
131
132
layers: [powertoolsLayer ],
132
133
});
133
134
}
0 commit comments