aws-cdk-lambda-poetry-asset


Nameaws-cdk-lambda-poetry-asset JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://github.com/jesse-peters/aws-cdk-lambda-poetry-asset
SummaryAWS CDK construct for packaging lambda functions with dependencies
upload_time2023-03-29 22:33:40
maintainer
docs_urlNone
authorJesse Peters
requires_python>=3.9,<4.0
licenseMIT
keywords aws cdk lambda construct poetry
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AWS CDK Lambda Poetry Asset

## About
This is the cdk v2 version of the original asset, which is available at [gitlab](https://gitlab.com/josef.stach/aws-cdk-lambda-asset).


AWS CDK currently supports 3 kinds of "Assets":

* [InlineCode](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.InlineCode.html) - useful for one-line-lambdas
* [AssetCode](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.AssetCode.html) - one-file lambdas without dependencies
* [S3Code](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.S3Code.html) - existing lambda packages already uploaded in an S3 bucket

There is, however, no support for more complex lambda function which require third party dependencies.
This repository presents one possible approach to lambda packaging.

The construct is aware of libraries bundled in the AWS lambda runtime and automatically removes those for you to save space.

It also counts with compiled C dependencies such as NumPy and takes care of library stripping.

By setting the `create_file_if_exists` to `False` you can use it with a caching system, like Github Actions `actions/cache@v3`. It will only run the build if the file doesnt exist at the output path already.

## Usage
Suppose your project's directory structure looks like this:
```
my-project
├── business_logic
│   └── backend.py
└── functions
    └── my_lambda.py
```

Then your stack would be:

```python
from pathlib import Path
from aws_cdk import aws_lambda
from aws_cdk_lambda_poetry_asset.zip_asset_code import ZipAssetCode

class MyStack(core.Stack):

    def __init__(self, app: core.App, id: str, **kwargs) -> None:
        super().__init__(app, id, **kwargs)
        work_dir = Path(__file__).parents[1]
        aws_lambda.Function(
            scope=self,
            id='MyLambda',
            code=ZipAssetCode(
                work_dir=work_dir,
                include=['functions', 'business_logic'],
                file_name='my-lambda.zip',
                create_file_if_exists=False
            )
            handler='functions/my_lambda.lambda_handler',
            runtime=aws_lambda.Runtime.PYTHON_3_9
        )
```
## Setup

#### [Install poetry](https://github.com/sdispater/poetry#installation)
```commandline
pip install poetry
```

#### Install dependencies
```commandline
poetry update
```

#### Run tests
Start docker first.
```commandline
poetry run pytest --cov-report term-missing --cov=aws_cdk_lambda_poetry_asset tests
```


## Create a release

This project will automatically create a github release when a PR is merged into the `main` branch. The title of the PR must adhere to [angular commit message format](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-format) in order for it to calculate a new version number.

### Example PR titles:

`feat: mindblowing feature`

`fix: bug thats been around for ever`

### Types
From angular documentation

Must be one of the following:

* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
* **ci**: Changes to our CI configuration files and scripts (example scopes: Circle, BrowserStack, SauceLabs)
* **docs**: Documentation only changes
* **feat**: A new feature
* **fix**: A bug fix
* **perf**: A code change that improves performance
* **refactor**: A code change that neither fixes a bug nor adds a feature
* **test**: Adding missing tests or correcting existing tests
## License
This code is released under MIT license.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jesse-peters/aws-cdk-lambda-poetry-asset",
    "name": "aws-cdk-lambda-poetry-asset",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "AWS,CDK,Lambda,Construct,Poetry",
    "author": "Jesse Peters",
    "author_email": "jesse@resist.bot",
    "download_url": "https://files.pythonhosted.org/packages/78/f0/0a742f1a3a517faedacf565eb461defd558af011b122b123c7ae81cd218a/aws_cdk_lambda_poetry_asset-0.5.1.tar.gz",
    "platform": null,
    "description": "# AWS CDK Lambda Poetry Asset\n\n## About\nThis is the cdk v2 version of the original asset, which is available at [gitlab](https://gitlab.com/josef.stach/aws-cdk-lambda-asset).\n\n\nAWS CDK currently supports 3 kinds of \"Assets\":\n\n* [InlineCode](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.InlineCode.html) - useful for one-line-lambdas\n* [AssetCode](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.AssetCode.html) - one-file lambdas without dependencies\n* [S3Code](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.S3Code.html) - existing lambda packages already uploaded in an S3 bucket\n\nThere is, however, no support for more complex lambda function which require third party dependencies.\nThis repository presents one possible approach to lambda packaging.\n\nThe construct is aware of libraries bundled in the AWS lambda runtime and automatically removes those for you to save space.\n\nIt also counts with compiled C dependencies such as NumPy and takes care of library stripping.\n\nBy setting the `create_file_if_exists` to `False` you can use it with a caching system, like Github Actions `actions/cache@v3`. It will only run the build if the file doesnt exist at the output path already.\n\n## Usage\nSuppose your project's directory structure looks like this:\n```\nmy-project\n\u251c\u2500\u2500 business_logic\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 backend.py\n\u2514\u2500\u2500 functions\n    \u2514\u2500\u2500 my_lambda.py\n```\n\nThen your stack would be:\n\n```python\nfrom pathlib import Path\nfrom aws_cdk import aws_lambda\nfrom aws_cdk_lambda_poetry_asset.zip_asset_code import ZipAssetCode\n\nclass MyStack(core.Stack):\n\n    def __init__(self, app: core.App, id: str, **kwargs) -> None:\n        super().__init__(app, id, **kwargs)\n        work_dir = Path(__file__).parents[1]\n        aws_lambda.Function(\n            scope=self,\n            id='MyLambda',\n            code=ZipAssetCode(\n                work_dir=work_dir,\n                include=['functions', 'business_logic'],\n                file_name='my-lambda.zip',\n                create_file_if_exists=False\n            )\n            handler='functions/my_lambda.lambda_handler',\n            runtime=aws_lambda.Runtime.PYTHON_3_9\n        )\n```\n## Setup\n\n#### [Install poetry](https://github.com/sdispater/poetry#installation)\n```commandline\npip install poetry\n```\n\n#### Install dependencies\n```commandline\npoetry update\n```\n\n#### Run tests\nStart docker first.\n```commandline\npoetry run pytest --cov-report term-missing --cov=aws_cdk_lambda_poetry_asset tests\n```\n\n\n## Create a release\n\nThis project will automatically create a github release when a PR is merged into the `main` branch. The title of the PR must adhere to [angular commit message format](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-format) in order for it to calculate a new version number.\n\n### Example PR titles:\n\n`feat: mindblowing feature`\n\n`fix: bug thats been around for ever`\n\n### Types\nFrom angular documentation\n\nMust be one of the following:\n\n* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)\n* **ci**: Changes to our CI configuration files and scripts (example scopes: Circle, BrowserStack, SauceLabs)\n* **docs**: Documentation only changes\n* **feat**: A new feature\n* **fix**: A bug fix\n* **perf**: A code change that improves performance\n* **refactor**: A code change that neither fixes a bug nor adds a feature\n* **test**: Adding missing tests or correcting existing tests\n## License\nThis code is released under MIT license.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "AWS CDK construct for packaging lambda functions with dependencies",
    "version": "0.5.1",
    "split_keywords": [
        "aws",
        "cdk",
        "lambda",
        "construct",
        "poetry"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b5b6e112c689d51d87a1b0136f445c2b00f7ebf0f7bb4d22ccf25e7f64067328",
                "md5": "9cc2cdec74423984ba037f9848ff27d0",
                "sha256": "088a6d0afbf24bbdc78a8ea8f2a0579c73491fcead4af8e0d3df8bb0b39b9474"
            },
            "downloads": -1,
            "filename": "aws_cdk_lambda_poetry_asset-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9cc2cdec74423984ba037f9848ff27d0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 7721,
            "upload_time": "2023-03-29T22:33:38",
            "upload_time_iso_8601": "2023-03-29T22:33:38.725483Z",
            "url": "https://files.pythonhosted.org/packages/b5/b6/e112c689d51d87a1b0136f445c2b00f7ebf0f7bb4d22ccf25e7f64067328/aws_cdk_lambda_poetry_asset-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "78f00a742f1a3a517faedacf565eb461defd558af011b122b123c7ae81cd218a",
                "md5": "cf9ee0c3503c9708b8a4d229c1d5b5fc",
                "sha256": "77517421f008c8f4b9379b2cd9486aa25ae67ed3546969a7162d4835eef5c57b"
            },
            "downloads": -1,
            "filename": "aws_cdk_lambda_poetry_asset-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "cf9ee0c3503c9708b8a4d229c1d5b5fc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 6847,
            "upload_time": "2023-03-29T22:33:40",
            "upload_time_iso_8601": "2023-03-29T22:33:40.526343Z",
            "url": "https://files.pythonhosted.org/packages/78/f0/0a742f1a3a517faedacf565eb461defd558af011b122b123c7ae81cd218a/aws_cdk_lambda_poetry_asset-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-29 22:33:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "jesse-peters",
    "github_project": "aws-cdk-lambda-poetry-asset",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aws-cdk-lambda-poetry-asset"
}
        
Elapsed time: 0.04921s