-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lambda: allow bundling of lambda layer #26332
Comments
Thank you for your feature request. Can you share more details about what your directory structure looks like? |
@pahud: It could look something like this:
Where in this case the But the same goes for any |
OK now I get it. Unfortunately lambda layer only support Code with no bundling capabilities. Please help us prioritize with upvotes 👍. |
btw Why not just |
probably related to #26107 (comment) |
@pahud: Using the full |
not sure is this issue outdated, i have bundling work for layer self.oracle_19_1_layer = lambda_.LayerVersion(
self,
"OracleDependency",
layer_version_name="oracle-dependency-19_1",
code=lambda_.Code.from_asset(
"./assets/lambda/oracle-19.1",
bundling=cdk.BundlingOptions(
image=lambda_.Runtime.PYTHON_3_9.bundling_image,
command=[
"bash",
"-c",
" && ".join(
[
f"pip install -r requirements.txt -t /{cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/python/lib/python3.9/site-packages",
f"cp -r ./lib /{cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/lib",
]
),
],
),
),
compatible_runtimes=[lambda_.Runtime.PYTHON_3_9],
license="Available under the MIT-0 license.",
description="A layer of oracle dependency",
) |
@jk2l Awesome! @JonWallsten does it work for you? |
I'm using Typescript so this particular code would not work. I'm on vacation, but I think I'm using esbuild to generate the bundle and then use Code.fromAsset. |
I would also be interested in using some of the const sharpLayer = new LayerVersion(this, 'sharpLayer', {
code: Bundling.nodeModules(['sharp']),
compatibleRuntimes: [Runtime.NODEJS_18_X, Runtime.NODEJS_20_X],
license: 'Apache-2.0',
description: 'Sharp layer',
}); |
Describe the feature
We are missing the bundling functionality when creating
LayerVersion
s in the CDK v2.Use Case
We have a lambda layer that uses imports from sibling/root folders (let say a shared util folder in root), but since they will not be included in the same output folder as the layer, these imports will be missing in runtime.
The same goes for node_modules. The modules used would have to be part of the assets target folder.
Bundling the layer takes care of this issue by making sure the imports are included in the bundle.
It also just includes the modules use since esbuild offers some treeshaking.
Proposed Solution
Offer the same bundling as the NodeJsFunction (also requested for Lambda @ Edge here: #14215).
Other Information
No response
Acknowledgements
CDK version used
2.87.0
Environment details (OS name and version, etc.)
Windows 10 x64. Node 18.12.x.
The text was updated successfully, but these errors were encountered: