Allow single files as Lambda code assets
See original GitHub issueCurrently, a Lambda code asset can either be a directory that is zipped and provided through the asset mechanism, or inline code that is limited to 4 kilobytes and supports only Python and Node.js. Inline code cannot be directly specified from a file, but it must first be read as string in the language runtime used, without the help of CDK. It would be nice to be able to specify a single file, that would automatically get added to a zip and be provided through the asset mechanism.
Use Case
Many Lambda functions are more complex than 4096 bytes, but still exist in a single file without any dependencies. It would be very convenient to be able to specify these as assets directly, instead of having to create multiple directories containing only that single file. Especially with layers, single file functions are very common.
Proposed Solution
Either allow the normal fromAsset
function to automatically zip single files:
lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler.py'))
Or provide a separate function, such as fromSingleAsset
or fromAssetZip
. The current magic of directories being automatically zipped and single files being automatically used without transformation is a bit confusing. Could also consider creating fromAssetDir
, fromAssetFile
and fromAssetZip
to make it very explicit what the intent is.
Other
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (4 by maintainers)
Top GitHub Comments
I like the idea of deprecating
fromAsset
and making explicit sugar functionsfromAssetDirectories(...dir: string[])
,fromAssetFiles(...files: string[])
andfromAssetZipFile(zip: string)
.Closing in favour of https://github.com/aws/aws-cdk/issues/4776