|
1 |
| -# Powertools for AWS Lambda Layer |
| 1 | +> [!important] |
| 2 | +> This repository will be archived on April 5, 2025 together with the `cdk-aws-lambda-powertools-layer` CDK constructs for Python and Node.js |
2 | 3 |
|
3 |
| -## Why this project exists |
| 4 | +Powertools for AWS will continue to provide official Lambda Layers for [Python](https://docs.powertools.aws.dev/lambda/python/latest/) and [TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/) in all commercial regions and GovCloud, as well as future regions as they become available. |
4 | 5 |
|
5 |
| -This is a custom construct that will create AWS Lambda Layer with Powertools for AWS Lambda for Python or NodeJS library. There are different |
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 |
8 |
| -and add it to your function. The construct is an extension of the |
9 |
| -existing [`LayerVersion`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LayerVersion.html) construct |
10 |
| -from the CDK library, so you have access to all fields and methods. |
| 6 | +### Your options |
11 | 7 |
|
12 |
| -> ⚠️ **This construct uses docker to build and bundle the dependencies!** |
| 8 | +**1. Use Managed Lambda layers (Recommended)** |
13 | 9 |
|
14 |
| -See the [API](API.md) for details. |
| 10 | +Powertools for AWS managed Lambda layers offer: |
| 11 | + |
| 12 | +- Optimization for each runtime and architecture |
| 13 | +- Ongoing support and updates |
| 14 | +- Availability across all commercial regions and GovCloud |
| 15 | +- Simplified workflow that lets you focus on function code |
15 | 16 |
|
16 |
| -```typescript |
17 |
| -import {LambdaPowertoolsLayer} from 'cdk-aws-lambda-powertools-layer'; |
18 |
| -import {RuntimeFamily } from "aws-cdk-lib/aws-lambda"; |
| 17 | +**2. Build Custom Lambda Layers** |
19 | 18 |
|
20 |
| - const powertoolsLayerPython = new LambdaPowertoolsLayer(this, 'TestLayer', {runtimeFamily: RuntimeFamily.PYTHON}); |
21 |
| - const powertoolsLayerNodeJS = new LambdaPowertoolsLayer(this, 'TestLayer', {runtimeFamily: RuntimeFamily.NODEJS}); |
22 |
| -``` |
| 19 | +If you need custom layers: |
23 | 20 |
|
24 |
| -Python |
| 21 | +- Use the open-source build pipeline from the main repositories |
| 22 | +- Reference our implementation for your own deployment process |
25 | 23 |
|
26 |
| -```python |
27 |
| -from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer |
28 | 24 |
|
29 |
| -powertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer') |
30 |
| -``` |
| 25 | +### Migration tips |
31 | 26 |
|
32 |
| -The layer will be created during the CDK `synth` step and thus requires Docker. |
| 27 | +- Plan your transition before the April 5, 2025 archival date |
| 28 | +- Test thoroughly with the managed layers before migrating production workloads |
| 29 | +- Review the documentation for [Python](https://docs.powertools.aws.dev/lambda/python/latest/) and [TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/) implementations |
33 | 30 |
|
34 |
| -## Install |
35 |
| - |
36 |
| -TypeSript/JavaScript: |
37 |
| - |
38 |
| -```shell |
39 |
| -npm i cdk-aws-lambda-powertools-layer |
40 |
| -``` |
41 |
| - |
42 |
| -Python: |
43 |
| - |
44 |
| -```shell |
45 |
| -pip install cdk-aws-lambda-powertools-layer |
46 |
| -``` |
47 |
| - |
48 |
| -## Usage |
49 |
| - |
50 |
| -### Python |
51 |
| - |
52 |
| -A single line will create a layer with Powertools for AWS Lambda (Python). For NodeJS you need to specifically set the `runtimeFamily: Runtime.NODEJS` property. |
53 |
| - |
54 |
| -```python |
55 |
| -from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer |
56 |
| - |
57 |
| -powertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer') |
58 |
| -``` |
59 |
| - |
60 |
| -You can then add the layer to your funciton: |
61 |
| - |
62 |
| -```python |
63 |
| -from aws_cdk import aws_lambda |
64 |
| - |
65 |
| -aws_lambda.Function(self, 'LambdaFunction', |
66 |
| - code=aws_lambda.Code.from_asset('function'), |
67 |
| - handler='app.handler', |
68 |
| - layers=[powertoolsLayer]) |
69 |
| -``` |
70 |
| - |
71 |
| -You can specify the powertools version by passing the optional `version` paramter, otherwise the construct will take the |
72 |
| -latest version from pypi repository. |
73 |
| - |
74 |
| -```python |
75 |
| -LambdaPowertoolsLayer(self, 'PowertoolsLayer', version='1.24.0') |
76 |
| -``` |
77 |
| - |
78 |
| -Additionally, powertools have extras depenedncies such as |
79 |
| -Pydantic, [documented here](https://awslabs.github.io/aws-lambda-powertools-python/latest/#lambda-layer). This is not |
80 |
| -included by default, and you have to set this option in the construct definition if you need it: |
81 |
| - |
82 |
| -```python |
83 |
| -LambdaPowertoolsLayer(self, 'PowertoolsLayer', include_extras=True) |
84 |
| -``` |
85 |
| - |
86 |
| -Full example: |
87 |
| - |
88 |
| -```python |
89 |
| -from aws_cdk import Stack, aws_lambda |
90 |
| -from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer |
91 |
| -from constructs import Construct |
92 |
| - |
93 |
| - |
94 |
| -class LayerTestStack(Stack): |
95 |
| - |
96 |
| - def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: |
97 |
| - super().__init__(scope, construct_id, **kwargs) |
98 |
| - |
99 |
| - powertoolsLayer = LambdaPowertoolsLayer( |
100 |
| - self, 'PowertoolsLayer', include_extras=True, version='1.24.0') |
101 |
| - |
102 |
| - aws_lambda.Function(self, 'LambdaFunction', |
103 |
| - code=aws_lambda.Code.from_asset('function'), |
104 |
| - handler='app.handler', |
105 |
| - layers=[powertoolsLayer]) |
106 |
| - |
107 |
| -``` |
108 |
| - |
109 |
| -### TypeScript |
110 |
| - |
111 |
| -Full example for TypeScript: |
112 |
| - |
113 |
| -```typescript |
114 |
| -import { Stack, StackProps } from 'aws-cdk-lib'; |
115 |
| -import { Construct } from 'constructs'; |
116 |
| -import { LambdaPowertoolsLayer } from 'cdk-aws-lambda-powertools-layer'; |
117 |
| -import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; |
118 |
| -import * as path from 'path'; |
119 |
| - |
120 |
| -export class CdkPowertoolsExampleStack extends Stack { |
121 |
| - constructor(scope: Construct, id: string, props?: StackProps) { |
122 |
| - super(scope, id, props); |
123 |
| - |
124 |
| - const powertoolsLayer = new LambdaPowertoolsLayer(this, 'TestLayer', { |
125 |
| - version: '1.22.0', |
126 |
| - includeExtras: true |
127 |
| - }); |
128 |
| - |
129 |
| - new Function(this, 'LambdaFunction', { |
130 |
| - code: Code.fromAsset(path.join('./function')), |
131 |
| - handler: 'app.handler', |
132 |
| - layers: [powertoolsLayer], |
133 |
| - }); |
134 |
| - } |
135 |
| -} |
136 |
| - |
137 |
| -``` |
| 31 | +### Connect |
138 | 32 |
|
| 33 | +If you have questions about the notice or about the migration to our managed Lambda layers, please reach out to |
| 34 | + |
| 35 | +- Powertools for AWS Lambda on Discord: #general - [Invite link](https://discord.gg/B8zZKbbyET) |
0 commit comments