AWS CDK Lambda Poetry Asset
About
This is the cdk v2 version of the original asset, which is available at gitlab.
AWS CDK currently supports 3 kinds of "Assets":
- InlineCode - useful for one-line-lambdas
- AssetCode - one-file lambdas without dependencies
- S3Code - 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:
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
pip install poetry
Install dependencies
poetry update
Run tests
Start docker first.
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 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.
Metadata
Release files for aws-cdk-lambda-poetry-asset 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aws_cdk_lambda_poetry_asset-0.5.2.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aws_cdk_lambda_poetry_asset-0.5.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / aws_cdk_lambda_poetry_asset-0.5.2.tar.gz
| Download URL | aws_cdk_lambda_poetry_asset-0.5.2.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6afe52acb57153554eec7cadf344574df41220298a9dc5bb0d8e82bb79cc06d
|
|
BLAKE2b-256 checksum How to use checksums |
6b2893d3b5a36cf796a0d5ee8b38e519dcfbb485b55349322dac457b1787857b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.15 tqdm/4.65.0 importlib-metadata/6.1.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.10
|
Release files / aws_cdk_lambda_poetry_asset-0.5.2-py3-none-any.whl
| Download URL | aws_cdk_lambda_poetry_asset-0.5.2-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
136c421354ddd805420dcdd12430f8b095a302775f508ade63436dd9cb9ab426
|
|
BLAKE2b-256 checksum How to use checksums |
82446921d447b1e0016b960d6dd4282bc1b8b80b38e4dbfffbfaeb3eac256852
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.15 tqdm/4.65.0 importlib-metadata/6.1.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.10
|