Skip to content
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

Allow single files as Lambda code assets #4428

Closed
1 of 2 tasks
nakedible opened this issue Oct 9, 2019 · 5 comments
Closed
1 of 2 tasks

Allow single files as Lambda code assets #4428

nakedible opened this issue Oct 9, 2019 · 5 comments
Assignees
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package feature-request A feature should be added or improved.

Comments

@nakedible
Copy link

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

@nakedible nakedible added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 9, 2019
@SomayaB SomayaB added the @aws-cdk/assets Related to the @aws-cdk/assets package label Oct 9, 2019
@NGL321 NGL321 removed the needs-triage This issue or PR still needs to be triaged. label Oct 11, 2019
@NGL321
Copy link
Contributor

NGL321 commented Oct 11, 2019

Hey @nakedible,

Thank you for submitting a request! This sounds like a reasonable feature to implement. Changing the functionality of fromAsset will likely introduce breaking changes, and therefore the path would likely be an additional function.

If you want to implement this, please feel free to put in a PR. Otherwise, someone will update this issue when any changes are made.

@nakedible
Copy link
Author

Since #4473 has landed, which has support for richer .dockerignore patterns, there is no need for this anymore. This is very simply achieved by:

      code: lambda.Code.fromAsset(".", {exclude: ["**", "!index.py"]}),

You can consider adding this example somewhere if you wish, or just closing this outright.

@eladb
Copy link
Contributor

eladb commented Oct 31, 2019

This is very cool! Thanks. Maybe we can add a little sugar that will make this easier to use.

@nmussy
Copy link
Contributor

nmussy commented 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).

@eladb eladb assigned nija-at and unassigned eladb Jan 23, 2020
@nija-at
Copy link
Contributor

nija-at commented Feb 5, 2020

Closing in favour of #4776

@nija-at nija-at closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

6 participants