# Powertools for AWS Lambda Layer
## Why this project exists
This is a custom construct that will create AWS Lambda Layer with Powertools for AWS Lambda for Python or NodeJS library. There are different
ways how to create a layer and when working with CDK you need to install the library, create a zip file and wire it
correctly. With this construct you don't have to care about packaging and dependency management. Create a construct
and add it to your function. The construct is an extension of the
existing [`LayerVersion`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LayerVersion.html) construct
from the CDK library, so you have access to all fields and methods.
> ⚠️ **This construct uses docker to build and bundle the dependencies!**
See the [API](API.md) for details.
```python
import {LambdaPowertoolsLayer} from 'cdk-aws-lambda-powertools-layer';
import {RuntimeFamily } from "aws-cdk-lib/aws-lambda";
const powertoolsLayerPython = new LambdaPowertoolsLayer(this, 'TestLayer', {runtimeFamily: RuntimeFamily.PYTHON});
const powertoolsLayerNodeJS = new LambdaPowertoolsLayer(this, 'TestLayer', {runtimeFamily: RuntimeFamily.NODEJS});
```
Python
```python
from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer
powertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer')
```
The layer will be created during the CDK `synth` step and thus requires Docker.
## Install
TypeSript/JavaScript:
```shell
npm i cdk-aws-lambda-powertools-layer
```
Python:
```shell
pip install cdk-aws-lambda-powertools-layer
```
## Usage
### Python
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.
```python
from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer
powertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer')
```
You can then add the layer to your funciton:
```python
from aws_cdk import aws_lambda
aws_lambda.Function(self, 'LambdaFunction',
code=aws_lambda.Code.from_asset('function'),
handler='app.handler',
layers=[powertoolsLayer])
```
You can specify the powertools version by passing the optional `version` paramter, otherwise the construct will take the
latest version from pypi repository.
```python
LambdaPowertoolsLayer(self, 'PowertoolsLayer', version='1.24.0')
```
Additionally, powertools have extras depenedncies such as
Pydantic, [documented here](https://awslabs.github.io/aws-lambda-powertools-python/latest/#lambda-layer). This is not
included by default, and you have to set this option in the construct definition if you need it:
```python
LambdaPowertoolsLayer(self, 'PowertoolsLayer', include_extras=True)
```
Full example:
```python
from aws_cdk import Stack, aws_lambda
from cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer
from constructs import Construct
class LayerTestStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
powertoolsLayer = LambdaPowertoolsLayer(
self, 'PowertoolsLayer', include_extras=True, version='1.24.0')
aws_lambda.Function(self, 'LambdaFunction',
code=aws_lambda.Code.from_asset('function'),
handler='app.handler',
layers=[powertoolsLayer])
```
### TypeScript
Full example for TypeScript:
```python
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { LambdaPowertoolsLayer } from 'cdk-aws-lambda-powertools-layer';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import * as path from 'path';
export class CdkPowertoolsExampleStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const powertoolsLayer = new LambdaPowertoolsLayer(this, 'TestLayer', {
version: '1.22.0',
includeExtras: true
});
new Function(this, 'LambdaFunction', {
code: Code.fromAsset(path.join('./function')),
handler: 'app.handler',
layers: [powertoolsLayer],
});
}
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/awslabs/cdk-aws-lambda-powertools-layer.git",
"name": "leo-cdk-aws-lambda-powertools-layer",
"maintainer": null,
"docs_url": null,
"requires_python": "~=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Amazon Web Services",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/de/64/ccf3e2140638abe9faaaa4c955515534bfae7504b39fb9663ebaed2ff1bf/leo-cdk-aws-lambda-powertools-layer-0.0.0.tar.gz",
"platform": null,
"description": "# Powertools for AWS Lambda Layer\n\n## Why this project exists\n\nThis is a custom construct that will create AWS Lambda Layer with Powertools for AWS Lambda for Python or NodeJS library. There are different\nways how to create a layer and when working with CDK you need to install the library, create a zip file and wire it\ncorrectly. With this construct you don't have to care about packaging and dependency management. Create a construct\nand add it to your function. The construct is an extension of the\nexisting [`LayerVersion`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.LayerVersion.html) construct\nfrom the CDK library, so you have access to all fields and methods.\n\n> \u26a0\ufe0f **This construct uses docker to build and bundle the dependencies!**\n\nSee the [API](API.md) for details.\n\n```python\nimport {LambdaPowertoolsLayer} from 'cdk-aws-lambda-powertools-layer';\nimport {RuntimeFamily } from \"aws-cdk-lib/aws-lambda\";\n\n const powertoolsLayerPython = new LambdaPowertoolsLayer(this, 'TestLayer', {runtimeFamily: RuntimeFamily.PYTHON});\n const powertoolsLayerNodeJS = new LambdaPowertoolsLayer(this, 'TestLayer', {runtimeFamily: RuntimeFamily.NODEJS});\n```\n\nPython\n\n```python\nfrom cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer\n\npowertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer')\n```\n\nThe layer will be created during the CDK `synth` step and thus requires Docker.\n\n## Install\n\nTypeSript/JavaScript:\n\n```shell\nnpm i cdk-aws-lambda-powertools-layer\n```\n\nPython:\n\n```shell\npip install cdk-aws-lambda-powertools-layer\n```\n\n## Usage\n\n### Python\n\nA single line will create a layer with Powertools for AWS Lambda (Python). For NodeJS you need to specifically set the `runtimeFamily: Runtime.NODEJS` property.\n\n```python\nfrom cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer\n\npowertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer')\n```\n\nYou can then add the layer to your funciton:\n\n```python\nfrom aws_cdk import aws_lambda\n\naws_lambda.Function(self, 'LambdaFunction',\n code=aws_lambda.Code.from_asset('function'),\n handler='app.handler',\n layers=[powertoolsLayer])\n```\n\nYou can specify the powertools version by passing the optional `version` paramter, otherwise the construct will take the\nlatest version from pypi repository.\n\n```python\nLambdaPowertoolsLayer(self, 'PowertoolsLayer', version='1.24.0')\n```\n\nAdditionally, powertools have extras depenedncies such as\nPydantic, [documented here](https://awslabs.github.io/aws-lambda-powertools-python/latest/#lambda-layer). This is not\nincluded by default, and you have to set this option in the construct definition if you need it:\n\n```python\nLambdaPowertoolsLayer(self, 'PowertoolsLayer', include_extras=True)\n```\n\nFull example:\n\n```python\nfrom aws_cdk import Stack, aws_lambda\nfrom cdk_aws_lambda_powertools_layer import LambdaPowertoolsLayer\nfrom constructs import Construct\n\n\nclass LayerTestStack(Stack):\n\n def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:\n super().__init__(scope, construct_id, **kwargs)\n\n powertoolsLayer = LambdaPowertoolsLayer(\n self, 'PowertoolsLayer', include_extras=True, version='1.24.0')\n\n aws_lambda.Function(self, 'LambdaFunction',\n code=aws_lambda.Code.from_asset('function'),\n handler='app.handler',\n layers=[powertoolsLayer])\n\n```\n\n### TypeScript\n\nFull example for TypeScript:\n\n```python\nimport { Stack, StackProps } from 'aws-cdk-lib';\nimport { Construct } from 'constructs';\nimport { LambdaPowertoolsLayer } from 'cdk-aws-lambda-powertools-layer';\nimport { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';\nimport * as path from 'path';\n\nexport class CdkPowertoolsExampleStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n\n const powertoolsLayer = new LambdaPowertoolsLayer(this, 'TestLayer', {\n version: '1.22.0',\n includeExtras: true\n });\n\n new Function(this, 'LambdaFunction', {\n code: Code.fromAsset(path.join('./function')),\n handler: 'app.handler',\n layers: [powertoolsLayer],\n });\n }\n}\n```\n",
"bugtrack_url": null,
"license": "MIT-0",
"summary": "Powertools for AWS Lambda layer for python and typescript",
"version": "0.0.0",
"project_urls": {
"Homepage": "https://github.com/awslabs/cdk-aws-lambda-powertools-layer.git",
"Source": "https://github.com/awslabs/cdk-aws-lambda-powertools-layer.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "93457730bed8d064dbe599fc376de17e8c489c711baa4c49e95586c0347db87b",
"md5": "70207b88fdcc658e76bc7863fab0e4d9",
"sha256": "4f2a5d0fecb4da86e0d89823393925ad09e0b4490c0ae02f0d7ac4103a2bf64d"
},
"downloads": -1,
"filename": "leo_cdk_aws_lambda_powertools_layer-0.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "70207b88fdcc658e76bc7863fab0e4d9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.8",
"size": 33393,
"upload_time": "2024-07-23T12:26:18",
"upload_time_iso_8601": "2024-07-23T12:26:18.975087Z",
"url": "https://files.pythonhosted.org/packages/93/45/7730bed8d064dbe599fc376de17e8c489c711baa4c49e95586c0347db87b/leo_cdk_aws_lambda_powertools_layer-0.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "de64ccf3e2140638abe9faaaa4c955515534bfae7504b39fb9663ebaed2ff1bf",
"md5": "064d68b74857e37e9bc89575cf2e31fd",
"sha256": "e1b8e970af44e7c7e092ae3b2844ff08d5d7b7ef39c699ff05bbeba3ebe24618"
},
"downloads": -1,
"filename": "leo-cdk-aws-lambda-powertools-layer-0.0.0.tar.gz",
"has_sig": false,
"md5_digest": "064d68b74857e37e9bc89575cf2e31fd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.8",
"size": 34605,
"upload_time": "2024-07-23T12:26:20",
"upload_time_iso_8601": "2024-07-23T12:26:20.549809Z",
"url": "https://files.pythonhosted.org/packages/de/64/ccf3e2140638abe9faaaa4c955515534bfae7504b39fb9663ebaed2ff1bf/leo-cdk-aws-lambda-powertools-layer-0.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-23 12:26:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "awslabs",
"github_project": "cdk-aws-lambda-powertools-layer",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "leo-cdk-aws-lambda-powertools-layer"
}