aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.62k stars 3.91k forks source link

core: support specifying included files for Code.from_asset #26107

Open rittneje opened 1 year ago

rittneje commented 1 year ago

Describe the feature

Add a property to Code.from_asset to indicate which particular files within the path should be included. If this property is present, only files matching the pattern will be considered. It is an error to specify this property if the path does not describe a directory.

Use Case

We have a bunch of Go lambda functions in one repository. We can easily compile multiple of them in parallel with go build -o $DIR my-module/cmd/.... However, this places all the binaries together in one directory. We would like to be able to reference this directory in Code.from_assets and filter it to only the particular binary name that goes with the Lambda function in question.

Currently we have to manually arrange for each binary to be in its own folder, which is really annoying.

Proposed Solution

No response

Other Information

No response

Acknowledgements

CDK version used

2.85.0

Environment details (OS name and version, etc.)

Alpine 3.18

pahud commented 1 year ago

Thanks for your use case sharing.

go-to-k commented 1 year ago

@pahud

Hi, Pahud!

I have a question for you on this issue. This issue's title is about aws_lambda, but the actual asset processing is done in the core module, so I think it should be done in core, what do you think?

Specifically, I am thinking of the following approach.

I haven't submitted a PR yet, but I've implemented it as a trial. I'll let you know what you think and make a decision.

https://github.com/aws/aws-cdk/compare/main...go-to-k:aws-cdk:feat/fs-copy-include-files

pahud commented 1 year ago

@go-to-k Yes this sounds like a good idea! Feel free to submit your PR draft for that, the maintainers would be happy to review your PR.

go-to-k commented 1 year ago

@pahud

Thank you! I will submit PR!

go-to-k commented 1 year ago

It was mentioned that the exclude property with a negation pattern could be used instead of using the include property, so the PR was closed.

https://github.com/aws/aws-cdk/pull/26365#issuecomment-1646054082

go-to-k commented 1 year ago

I also submitted the PR for the docs of exclude property using a negation.