cdk-aws-lambda-powertools-layer


Namecdk-aws-lambda-powertools-layer JSON
Version 3.7.0 PyPI version JSON
download
home_pagehttps://github.com/awslabs/cdk-aws-lambda-powertools-layer.git
SummaryPowertools for AWS Lambda layer for python and typescript
upload_time2023-11-15 09:48:28
maintainer
docs_urlNone
authorAmazon Web Services
requires_python~=3.7
licenseMIT-0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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": "cdk-aws-lambda-powertools-layer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "~=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Amazon Web Services",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/f0/62/094e42eb12d77ebdf6d14f6f36afae570efbe904410a4eee60ea09a4ea0d/cdk-aws-lambda-powertools-layer-3.7.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": "3.7.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": "a23ffa4637c2c8b9701974f4e19c105a60aa8d0b92ce896c1ca1df51e5488f90",
                "md5": "9b82f93f09f63920074cf5a37018bfbc",
                "sha256": "353b010f0681a6d626721ce8f934fe17a649f845fefb276ea7451cfa1932b19e"
            },
            "downloads": -1,
            "filename": "cdk_aws_lambda_powertools_layer-3.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b82f93f09f63920074cf5a37018bfbc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "~=3.7",
            "size": 31759,
            "upload_time": "2023-11-15T09:48:26",
            "upload_time_iso_8601": "2023-11-15T09:48:26.568734Z",
            "url": "https://files.pythonhosted.org/packages/a2/3f/fa4637c2c8b9701974f4e19c105a60aa8d0b92ce896c1ca1df51e5488f90/cdk_aws_lambda_powertools_layer-3.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f062094e42eb12d77ebdf6d14f6f36afae570efbe904410a4eee60ea09a4ea0d",
                "md5": "dfc8b5cedb5bc2603f88047fb70cd73e",
                "sha256": "1225f8f9086412a620fb27fe59de5537456d636b435b496bffc76e544b1fda1f"
            },
            "downloads": -1,
            "filename": "cdk-aws-lambda-powertools-layer-3.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "dfc8b5cedb5bc2603f88047fb70cd73e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.7",
            "size": 32923,
            "upload_time": "2023-11-15T09:48:28",
            "upload_time_iso_8601": "2023-11-15T09:48:28.164414Z",
            "url": "https://files.pythonhosted.org/packages/f0/62/094e42eb12d77ebdf6d14f6f36afae570efbe904410a4eee60ea09a4ea0d/cdk-aws-lambda-powertools-layer-3.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-15 09:48:28",
    "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": "cdk-aws-lambda-powertools-layer"
}
        
Elapsed time: 0.14487s