question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to deploy AWS Lambda function due to huge size on dependencies

See original GitHub issue

Bug description

I have an AWS Lambda function. Unable to deploy it since I started working with Prisma. I have uninstalled both “prisma” and “@primsa/client” to see how much is the increase when installing.

node_modules before installing prisma as a devDependency: 65MB

node_modules after “yarn add prisma --dev”: 167MB

node_modules after “yarn add @prisma/client”: 338MB

This makes it impossible to deploy the Lambda function due to the 262144000 bytes maximum size allowed.

I am not using any framework. Just using a fresh AWS CDK project and inside the function folder package the following dependencies:

"dependencies": { "@prisma/client": "^2.21.2" }, "devDependencies": { "aws-sdk": "^2.826.0", "prisma": "^2.21.2" }

If you need any additional information I can provide it will be a pleasure to help.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
janpiocommented, Apr 30, 2021

When deploying manually to Lambda, you need to make sure your archive only includes the necessary dependencies. (Development dependencies usually are not for example, many other are also not needed)

Here is an example script how we achieve that manually in our end to end tests:

rm -rf node_modules
yarn install --production

rm -rf lambda.zip

rm -rf node_modules/prisma
rm -rf node_modules/@prisma/engines
rm -rf node_modules/typescript

zip -r lambda.zip index.js prisma/schema.prisma node_modules/.prisma node_modules/**

du -b ./lambda.zip

https://github.com/prisma/e2e-tests/blob/dev/platforms-serverless/lambda/zip.sh

In the schema file of that project we have binaryTargets = ["native", "rhel-openssl-1.0.x"]. If necessary we could/would also remove the native binary before upload here (either by removing it from the schema before generation, or removing the files in the script).

Does this work for you?

If you use something like Serverless Framework or deploy to Netlify or Vercel Functions, their tooling will take care of this automatically.

PS: We are missing documentation on how to typically do this for now - we will work on that in the future so your feedback will be super valuable here.

3reactions
janpiocommented, Dec 20, 2022

Today’s release 4.8.0 has significantly (average 50%, on some platforms even more) decreased the size of our engine files:

Improved serverless experience — smaller engines size

In this release, we have decreased the size of our engine files by an average of 50%. The size of the Query Engine used on Debian, with OpenSSL 3.0.x, for example, went from 39MB to 14MB. We will also remove some smaller engines to decrease the total size in future versions.

Additionally, we have started optimizing how the Prisma schema is loaded in Prisma Client. You should notice a considerable improvement when executing the first query if you’re working with a bigger schema with many models and relations.

We will continue investing in this direction in the next releases and further improve the experience with Prisma and serverless environments.

https://github.com/prisma/prisma/releases/tag/4.8.0

We know we still have duplicated engine files in multiple locations, and that we are including too many of our engine files - but this was the obvious place to start and we are happy how significantly we could improve the situation already. Expect more updates like this in the coming releases from us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Ways to Overcome AWS Lambda Deployment Size Limit
Most of the workarounds boil down to one key idea: to move the large files or large dependencies away from the function code...
Read more >
SAM Deployment Fails with Size Issue For Lambda Function
Try accessing it through the AWS SDK rather and see if you can get your Lambda function smaller. In the end the bigger...
Read more >
Lambda deployment packages - AWS Documentation
Deployment packages over 50 MB. If your deployment package is larger than 50 MB, upload your function code and dependencies to an Amazon...
Read more >
Reduce your package size when uploading a Lambda function
Much better if you are using Serverless Framework (or SAM or Terraform) or the AWS CDK: they will take care of bundling the...
Read more >
AWS Lambda Limits to Keep in Mind When Developing a ...
Total Size Of All Deployment Packages ... In your AWS account, you will have a region wide soft limit of 75GB for all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found