"markdown": "# Lambda powertools python layer\n\n## Why this project exists\nThis is a custom construct that will create AWS Lambda Layer with AWS Powertools for Python library.\nThere 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.\nWith this construct you don't have to care about packaging and dependency management, just create a construct and add it to your function.\nThe construct is an extension of the existing [`LayerVersion`](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.LayerVersion.html) construct from the CDK library, so you have access to all fields and methods.\n\n```typescript\nimport { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-layer';\n\nconst powertoolsLayer = new LambdaPowertoolsLayer(this, 'TestLayer');\n```\n\n## How to test\n\nThis module is not published yet, therefore you need to install few tools to test it.\nThis section will be deleted after the construct is released to a public repository.\n\n### Requirements\n\n* cdk v2\n* docker\n* npm or yarn, whatever you prefer\n\n### Build construct\n\nAfter you have checked out the repo:\n\n```shell\nnpm i\nnpm run build\n```\n\nThis will create a tgz file in `dist/js` directory. You can copy this file to your test project then install this module\nwith\n\n```shell\nnpm i file:PATH_TO_PACKAGE/
[email protected]\n```\n\n## Install\n\nTypeSript/JavaScript:\n\n```shell\nnpm i cdk-lambda-powertools-python-layer\n```\n\nPython:\n\n```shell\npip install cdk-lambda-powertools-python-layer\n```\n\n## Usage\n\nA single line will create a layer with powertools for python:\n\n```typescript\nimport { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-layer';\n\nconst powertoolsLayer = new LambdaPowertoolsLayer(this, 'TestLayer', {\n version: '1.22.0',\n});\n```\n\nYou can then add the layer to your funciton:\n\n```typescript\nnew Function(this, 'LambdaFunction', {\n code: Code.fromAsset(path.join('./function')),\n handler: 'app.handler',\n runtime: Runtime.PYTHON_3_9,\n layers: [powertoolsLayer],\n});\n```\n\nYou can specify the powertools version by passing the optional `version` paramter, otherwise the construct will take the latest\nversion from pypi repository.\n\n```typescript\nnew LambdaPowertoolsLayer(this, 'PowertoolsLayer', {\n version: '1.21.0'\n});\n```\n\nAdditionally, powertools have extras depenedncies such as Pydantic, [documented here](https://awslabs.github.io/aws-lambda-powertools-python/latest/#lambda-layer).\nThis is not included by default, and you have to set this option in the construct definition if you need it:\n\n```typescript\nnew LambdaPowertoolsLayer(this, 'PowertoolsLayer', {\n includeExtras: true\n});\n```\n\nFull example:\n\n```typescript\nimport { Stack, StackProps } from 'aws-cdk-lib';\nimport { Construct } from 'constructs';\nimport { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-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 runtime: Runtime.PYTHON_3_9,\n layers: [powertoolsLayer],\n });\n }\n}\n\n```\n"
0 commit comments