supersan
supersan

Reputation: 6141

How to decrease the size of serverless deploy?

I'm deploying an aws lambda function using serverless framework. My problem is there is a large file (44MB) that is deployed every time I do sls deploy -f any_fn. I've had similar problems when there is a node_modules folder (which can be quite big).

Is there a way to reduce the upload size by uploading the common files only once (and for all functions)? Because right now it keeps zipping and deploying that same binary file again and again though it never changes.

Upvotes: 1

Views: 3093

Answers (4)

Felipe Gené
Felipe Gené

Reputation: 1

Use lambda containers and your problems will be solved! Lambda containers have a 10 GB image size limmit! You can add anything you want in there! I've made many express apps with Serverless http and lambda containers. You can also add an efs to your lambda and acess your files from there. Check this tutorial

Upvotes: 0

Anant Sharma
Anant Sharma

Reputation: 1

You can try using lambda layers. All you need to do is create separate serverless project for dependencies management for ex. node_modoles and rest of the services will refer to it (follow docs). This should reduce the deployment or package size of individual lambda significantly.

Upvotes: 0

elirandav
elirandav

Reputation: 2063

This was my solution:

  1. Upload the large files to S3 bucket.
  2. Download all S3 files in a function executed under the global scope, not in the scope of exports.handler so the code will be executed only one time (for container).
  3. To make sure re-use of the container you should keep the lambda warm using CloudWatch timer with two simple steps.

This allow you to deploy only the small files.

Upvotes: 1

Mark B
Mark B

Reputation: 200501

There's no way to do what you propose. AWS Lambda requires you to upload the entire package including all dependencies each time. Everything has to be inside the zip file that is deployed to Lambda.

Upvotes: 2

Related Questions