question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow single files as Lambda code assets

See original GitHub issue

Currently, 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
nmussycommented, Oct 31, 2019

I like the idea of deprecating fromAsset and making explicit sugar functions fromAssetDirectories(...dir: string[]), fromAssetFiles(...files: string[]) and fromAssetZipFile(zip: string).

0reactions
nija-atcommented, Feb 5, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Assets - AWS Cloud Development Kit (AWS CDK) v2
Assets are local files, directories, or Docker images. ... It also creates a Lambda function with the local directory asset as the code...
Read more >
5 Ways To Bundle a Lambda Function Within an AWS CDK ...
This post explains how to bundle or include a Lambda function within a CDK construct if your function requires external dependencies.
Read more >
Lambda can't find modules from outer folders when deployed ...
If your lambda function uses dependencies, you'll have to package everything into a ZIP file and tell CDK where to find the ZIP....
Read more >
How to Create an AWS Lambda Function with CDK ... - YouTube
In this video, I walk you through the steps to create an AWS Lambda function using CDK. I walk you through the process...
Read more >
How to Create AWS CDK Lambda Functions? 4 Easy Steps
lambda.Code.fromAsset(path): This allows you to mention a directory or a .zip file in your local filesystem which will be zipped and uploaded to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found