-
Notifications
You must be signed in to change notification settings - Fork 820
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
Python lambda is 2.6mb when there is 0 dependencies #5566
Comments
Amplify CLI uses pipenv to bundle the resources to the cloud. Pipenv brings in virtual env, which adds size to the bundle. |
@yuth And FYI, Amplify does not even support Python 3.8 |
@michaelbrewer You're right that pipenv is overkill for small functions that only have a couple dependencies, but it is good for managing functions with lots of dependencies. It is also a well adopted package management tool in the python ecosystem: https://packaging.python.org/tutorials/managing-dependencies/. We don't use AWS SAM because many of our customers don't use / have SAM installed. We do support Python 3.8, so if you are having trouble there please open an issue with details of the problem. |
amplify console does not support Python 3.8 Most lambdas don't need many dependencies (and some have none at all outside of AWS SDK) So in most cases just have a requirements.txt should be all that you would need. Larger projects can use poetry. |
@edwardfoyle Here is the example lambda for python function for a cognito auth challenge: def handler(event: dict, _):
print("event", event)
if len(event["request"]["session"]) == 0:
event["request"]["challengeMetadata"] = "COOKIE_CHALLENGE"
event["request"]["publicChallengeParameters"] = {}
event["request"]["publicChallengeParameters"]["cookieName"] = "source"
event["request"]["privateChallengeParameters"] = {}
return event I would expect the deployed lambda to be tiny |
Note how AWS-CDK does this without bloating the lambda with unused libraries : https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda-python As a develop you just need to have Docker installed. |
@edwardfoyle @yuth - will anyone look into fixing this? I can see that AWS does care about the cost of cold starts (https://aws.amazon.com/blogs/developer/modular-aws-sdk-for-javascript-release-candidate/), and this seems to be inconsistent. |
@michaelbrewer We'll look into this. Sorry for the late response. |
Maybe @heitorlessa has some input on how to support Python lambdas in a clean way. It would be nice to support SAM or do what CDK does when building Lambda functions (while keeping the size down) |
Hopefully the tools improves soon. As we are planing to build all of our lambdas in Python |
@kaustavghosh06 while I don't have the bandwidth to contribute code I'm happy to review or chat You can keep pipenv but only extract the dependencies themselves instead of bringing the whole virtual env - it's not necessary. pipenv here will also break when customers bring dependencies that rely on C, as it needs to build within a Linux env -- hence Docker suggestion by Michael (a flag would do). |
Thanks @heitorlessa for offering an ear for this. I do like how sam can bootstrap a lambda with the build tools and sample code:
Maybe this can be an option @kaustavghosh06 . When can we expect to at least not bring the whole virtual env with the lambda? |
@kaustavghosh06 what is the timeline on this? Otherwise |
RE: Oh i see that this is a separate issue (which is NOT being fixed): |
@eddiekeller @kaustavghosh06 - is anyone looking into this? How easy would it be to fix this ourselves in the CLI? |
How about doing something along the lines of : # Create an requirements.txt in src/ (which can be gitignored)
pipenv lock -r > src/requirements.txt Then build/download the dependencies using docker image # Download the vendored deps
pip install -r requirements.txt -t /vendored && cp -au . /vendored |
Found a hack to make amplify stop building all these nondependent-dependencies into my Python functions. This will only work for functions that do not have any dependencies that aren't already provided in lambda layers, as it just completely stops the function build process. There is an amplify.state file inside of each function. If you don't want amplify to build your function, modify the
|
Same Issue Here |
There is a comment on an alternative way to run pipenv in the following comment which allows installation of dependencies without copying the virtualenv. Ideally the amplify project may use this method instead: |
Amplify is still including the pipenv venv bundle in function deployments? Is this a joke? |
Describe the bug
When create a function with a very simple Python lambda, the generated lambda is 2MB
Amplify CLI Version
4.30.0
To Reproduce
Take pointless lambda like this and build it.
Expected behavior
The deployed lambda should only be a couple bytes not 2.6mb
Screenshots
Desktop (please complete the following information):
Mac
node -v
to check the node version on your systemv14.13.1
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: