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

Lambda: make it easier to specify a list of files and directories instead of a directory for code assets #4776

Closed
eladb opened this issue Oct 31, 2019 · 14 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@eladb
Copy link
Contributor

eladb commented Oct 31, 2019

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.

Originally posted by @nakedible in #4428 (comment)

@eladb eladb added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. @aws-cdk/aws-lambda Related to AWS Lambda labels Oct 31, 2019
@eladb
Copy link
Contributor Author

eladb commented Feb 5, 2020

Still think we should provide first class api for this

@nija-at nija-at changed the title Lambda: make it easier to specify a list of files instead of a directory for code assets Lambda: make it easier to specify a list of files and directories instead of a directory for code assets Feb 6, 2020
@melnikalex
Copy link

I don't know if this is related, but I'd like to also be able to upload a directory without zipping it. Is this feasible, already possible?

@eladb
Copy link
Contributor Author

eladb commented Mar 5, 2020

@melnikalex check out the s3-deployment module for that.

@ospfranco
Copy link

ospfranco commented Mar 15, 2020

I just tried using this, at first it seemed to work fine, but I just realized that when I try to deploy, the latest version of my lambda is not detected.

I do some changes to the file, then run either cdk diff or cdk deploy and all I get are no changes, so I think the sourceHash is not being correctly generated...

A simple SHOULD workaround is passing a different source hash everytime, here is a dummy implementation since I don't want to use this forever or calculate the hash myself:

return new lambda.AssetCode(DIST_FOLDER, { exclude: ["**", `!${fileName}.js`], sourceHash: new Date().toISOString() });

then doing cdk diff does detect there is some changes, however when I run the lambda I only get the old code running...

EDIT: I can confirm this is happening, I just refactored my code to adhere to the old way of doing things (packaging an entire folder) and things are working as expected, looking forward to this feature though, mighty useful if you are using webpack and packaging lambdas into a single file

@nija-at nija-at added the p2 label Aug 18, 2020
@yogur
Copy link

yogur commented Feb 11, 2021

How do I whitelist a directory from exclusion?

Whitelisting a file by using "!index.py" works. However, whitelisting a directory is not working. I tried "!/dir/**", "!/dir", "!/dir/*", "!dir" but non of them are working.

@Liooo
Copy link

Liooo commented Mar 11, 2021

@yogur

alright this worked for me

lambda.Code.fromAsset(".", {exclude: ['**', '!dir', '!dir/*']})

@jjrv
Copy link

jjrv commented May 15, 2021

The exclude option is deprecated, is there a better alternative?

@zacyang
Copy link

zacyang commented Nov 11, 2021

The document is not even mention what is replacing it, just deprecate it....wat...

@ghost
Copy link

ghost commented Nov 18, 2021

I've been using this heavily and also just noticed it's been deprecated... Is there an existing alternate or one in the works? Thanks!

@israelg99
Copy link

Update on this?

@OGoodness
Copy link

+1

1 similar comment
@vmarinescu
Copy link

+1

@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels May 12, 2023
@maddyexplore
Copy link

Still not getting the file wise assert adding feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests