Open anentropic opened 11 months ago
TBH I'd love to be able to run the tests without needing docker at all ...I don't see why it should be needed until doing the actual deployment
You're right, this should happen at synth time (or just before).
It doesn't look like there's a good workaround to keep this from happening other than not importing a package, but that's not feasible. However, I don't know how wide the effect of this is; if other customers have serious issues with this happening, we can probably raise it from p2 to p1.
I was able to reproduce it with the minimal code above, so I guess others should be able to too
and if not maybe we have a clue about if there's something weird on my end (I haven't tried to do anything weird, but who knows)
One possible solution can be to make BundingOptions.image
lazy, i.e. something like getImage: () => DockerImage
. and then call the lazy function when a bundling actually happens to get a build image.
We need to find a way to introduce such change without breaking something. I'm willing to work on this :)
The thing that makes this situation even more annoying is that it doesn't appear to use any caching from the Docker engine... every time I run any cdk command on my stack it has to go and build the docker images from scratch
Describe the bug
I have a python cdk codebase
I added a
aws_lambda_python_alpha.PythonFunction
to my stack... now as soon as I instantiate the stack containing that Lambda, a docker build gets triggeredExpected Behavior
I would expect that docker build for the Lambda function would only occur during deployment, or at worst during synth phase
docker build at import time feels like a bug
Current Behavior
the docker build occurs at the point that the
aws_lambda_python_alpha.PythonFunction
gets instantiatedso it happens just by importing the code
in particular it happens when I run unit tests for the cdk codebase, which instantiate a version of the stack multiple times
a) makes my tests very slow 😢 b) it's also noisy - it prints a bunch of output to stderr:
Reproduction Steps
app.py
infra/assets/repro/src/index.py
infra/assets/repro/src/requirements.txt
(empty file)Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.106.1 (build a2e5f65)
Framework Version
2.108.0
Node.js Version
v18.18.0
OS
macOS 14.1
Language
Python
Language Version
3.11.5
Other information
No response