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

aws-lambda-python-alpha: PythonFunction requires 4 minutes to build and produces a 3GB Docker image #32682

Open
1 task
garysassano opened this issue Dec 29, 2024 · 3 comments
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. effort/medium Medium work item – several days of effort p3

Comments

@garysassano
Copy link

Describe the bug

The Docker image for this Lambda function was built on an AMD Ryzen 5 7600X CPU.

The resulting image size of 3GB is highly excessive, especially considering that the final Lambda function deployment package is only 3.6MB.

image

image

image

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

See above.

Current Behavior

See above.

Reproduction Steps

See above.

Possible Solution

Refactor the Dockerfile.

Additional Information/Context

Related issue: #32413

CDK CLI Version

2.173.3

Framework Version

No response

Node.js Version

22.12.0

OS

Ubuntu 24.04.1

Language

TypeScript

Language Version

No response

Other information

No response

@garysassano garysassano added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 29, 2024
@pahud pahud self-assigned this Dec 30, 2024
@pahud
Copy link
Contributor

pahud commented Dec 30, 2024

I tried to simply build up the vended Dockerfile and it took me 2.1GiB disk space.

 % finch images | grep test
test      latest   
6c59e57c9c7e    10 seconds ago    linux/amd64    2.1 GiB      719.8 MiB

Yes we should figure out if there's anything we can improve the bundling procedure. Any ideas welcome and appreciated.

@pahud pahud added effort/medium Medium work item – several days of effort p3 labels Dec 30, 2024
@pahud pahud removed their assignment Dec 30, 2024
@pahud pahud removed the needs-triage This issue or PR still needs to be triaged. label Dec 30, 2024
@garysassano
Copy link
Author

I can confirm that the expected size of the Docker build image is approximately 2.1GB. However, in my case, it seems that some additional folders were unintentionally copied into the image.

Out of curiosity, I tried uninstalling esbuild locally to observe the impact of Docker bundling for a NodejsFunction. Unfortunately, the result is the same, as others have already pointed out in #19230.

I honestly think it has gotten worse over time with the addition of more package managers to the image. Personally, I'd aim for a separate Dockerfile tailored to each package manager, along with bundling logic in CDK that's specific to that package manager. I'd also steer clear of the AWS SAM image, which feels overly bloated.

What takes about 2m and a half with Docker bundling is completed in 1s or less without it.

image

@garysassano
Copy link
Author

I'm currently using a uv-specific Dockerfile that could reduce docker build image size by over 13x, and it works like a charm.

As you can see, it's blazing fast.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. effort/medium Medium work item – several days of effort p3
Projects
None yet
Development

No branches or pull requests

2 participants