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.

Large package size when compiling for lambda

See original GitHub issue

Bug description

Hi There,

I’m looking at using Prisma in a lambda environment and have noticed the package size is around 250Mb when using the following generator:

generator client {
    provider      = "prisma-client-js"
    binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

I’m using the following package.json and am installing using npm ci --omit=dev (have also tried npm ci --production)

"devDependencies": {
    "prisma": "^4.1.0",
    "typescript": "~4.3.0"
  },
  "dependencies": {
    "@prisma/client": "^4.1.0"
  }

Wanted to check that this is the intended package size, and if it is, whether there are any files I can manually delete to minimise the package size.

I came across this article however we use AWS SAM and don’t want to introduce webpack solely to support prisma.

Thanks in advance for your help

How to reproduce

  1. Create an npm package with the above dependencies
  2. Use the prisma generator config above
  3. Run npm ci --omit=dev to install production dependencies
  4. The node_modules package will be > 150Mb

Expected behavior

The node_modules package is small enough (preferably < 30Mb) to deploy in a lambda function without using layers

Prisma information

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: 14.9
  • npm: 8.14

Prisma Version

^4.1.0

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
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.

0reactions
Jolg42commented, Aug 19, 2022

@cam-slyp If you are using AWS Lambda only, you could do the following

  1. Create a zip script that only zips what’s needed, for example https://github.com/prisma/ecosystem-tests/blob/dev/platforms-serverless/lambda/zip.sh
  2. Then upload the zip
aws lambda update-function-code --function-name my-function --zip-file "fileb://lambda.zip"

Note: In our docs we mention how to remove these unneeded artifacts but only when using the serveless framework, I think we could improve that and mention how to do that when using AWS Lambda alone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to increase the maximum size of the AWS lambda ...
You can load libraries or packages that are larger than the 250 MB package deployment size limit of AWS Lambda using EFS.
Read more >
Reduce your package size when uploading a Lambda function
How to keep the package size you are uploading small? · removes all the devDependencies: npm install --production or even better (and faster!)...
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 >
Minimizing AWS Lambda deployment package size in ...
At the time of writing of this article, deployment package size limits are 50 MB for zipped and 250 MB for unzipped functions...
Read more >
AWS Lambda Limits to Keep in Mind When Developing a ...
There is a hard limit of 50MB for compressed deployment package with AWS Lambda and an uncompressed AWS Lambda hard limit of 250MB....
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