aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.55k stars 3.87k forks source link

aws-lambda-python-alpha: BundlingOptions exclude all assets and explicit include #30652

Open mayconfrr opened 3 months ago

mayconfrr commented 3 months ago

Describe the feature

Add a mode to BundlingOptions where it will import only a explicit written list of files/directories as opposed to the current pattern using asset_excludes

Use Case

I propose adding a mode to the BundlingOptions in the CDK that allows for specifying assets to include explicitly, rather than excluding assets. This inclusion mode will simplify configurations where only a few files or directories need to be bundled, enhancing clarity and reducing configuration complexity.

This feature will benefit AWS Lambda functions by potentially reducing deployment package size, thereby improving cold start times.

Here's some example of my current configuration and as can be seen, this can be tedious as more libraries are included

PythonFunction(
            **other_atributes,
            bundling=BundlingOptions(
                asset_excludes=[
                    ".git",
                    ".idea",
                    ".mypy_cache",
                    ".pytest_cache",
                    ".ruff_cache",
                    ".venv",
                    ".vscode",
                    "cdk.out",
                    "cdk",
                    "node_modules",
                    "tests",
                    ".coverage",
                    ".coveragerc",
                    ".gitignore",
                    ".pre-commit-config.yaml",
                    "app.py",
                    "bitbucket-pipelines.yml",
                    "cdk.context.json",
                    "cdk.json",
                    "coverage.xml",
                    "package.json",
                    "package-lock.json",
                    "poetry.toml",
                    "README.md",
                ]
            ),
        )

Proposed Solution

Add an asset_includes attribute to BundlingOptions that works similarly to asset_excludes but specifies which assets to include, and have both options mutually exclusive

Other Information

No response

Acknowledgements

CDK version used

2.144.0

Environment details (OS name and version, etc.)


pahud commented 2 months ago

Makes sense to me. Please help us prioritize this feature request with 👍 and we welcome pull requests.