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.71k stars 3.94k forks source link

s3-assets: local bundling does not work #26581

Open rittneje opened 1 year ago

rittneje commented 1 year ago

Describe the bug

aws_cdk.BundlingOptions has a property local that we can use to define a "local" bundler instead of routing through docker. However, it is broken.

First, the Python docs show the completely wrong signature for ILocalBundling.try_bundle:

try_bundle(output_dir, *, image, bundling_file_access=None, command=None, entrypoint=None, environment=None, local=None, network=None, output_type=None, platform=None, security_opt=None, user=None, volumes=None, volumes_from=None, working_directory=None)

In reality, the signature needs to be the same as in TypeScript:

try_bundle(self, output_dir: str, options: aws_cdk.BundlingOptions) -> bool:

Even after getting through that issue, it seems that the local bundling concept was not designed properly. None of the input parameters tell you what you are intending to bundle. With docker I believe that comes through as the working directory, but the local bundler gets nothing. The working directory (at least on the Python side) is not changed, and there is no parameter for it either. So essentially the only way to do it is to make a separate bundler instance for each aws_lambda.Code.from_asset invocation, and duplicate the path in its constructor. It is also unclear to me how any of this is intended to work with the exclude and follow_symlinks parameters since they don't come through either.

I will also point out the documentation around local bundling is extremely inadequate. https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_s3_assets/README.html#asset-bundling

Expected Behavior

The Python docs should be accurate. The local bundling feature should be properly designed and tested, with relevant documentation available.

Current Behavior

Does not work in any reasonable sense.

Reproduction Steps

Try to use it.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.85.0 (build 4e0d726)

Framework Version

No response

Node.js Version

v18.16.1

OS

Alpine 3.18

Language

Python

Language Version

Python 3.11.4

Other information

No response

pahud commented 1 year ago

Thank you for your report. I believe the local bundling is still very experimental and we appreciate any PR to improve that.

rittneje commented 1 year ago

@pahud if it’s experimental, will breaking changes to the ILocalBundling interface be accepted to make it usable?

rittneje commented 1 year ago

@pahud

jwshyns commented 1 year ago

I second the concerns of @rittneje - this functionality has been available in this non-working state for quite some time without a crumb of documentation alluding to the fact it's experimental or that there are known limitations or issues. Short of fixing this functionality, it would be great to see any mention of these issues in the documentation.