Search code examples
node.jsaws-lambdaserverless

Change maximum size of AWS lambda


I tried to deploy my Serverless function on AWS lambda, but I got this error:

Unzipped size must be smaller than 262144000 bytes.

I can't lower function size, because there is trained machine learning model (about 400Mb).

Is there any way to increase maximum lambda size?


Solution

  • Update June 2022

    The local Lambda storage in /tmp can now be expanded to up to 10GB instead of the 512MB as mentioned in my answer.


    If your model is 400MB you won't be able to upload it with your Lambda or in a layer.

    From my point of view you have three options:

    1. Put the model on S3 and download it when the Lambda is initialised to /tmp. Unfortunately, you only have 512MB in /tmp. Should your model increase its size beyond this, this won't work anymore.
    2. Use the new feature to run Docker images from ECR as Lambda. Therefore, you could create a Docker image that already contains your model and run it.
    3. Mount an EFS volume to your Lambda, which contains the model. EFS volumes can more or less be as large as you want (see limits).

    All of those solutions increase the complexity of your solution. I think the S3 solution (option 1) is the easiest to do, but might get in you int trouble in the future. It will also increase your cold start time considerably, because your Lambda has to download 400MB.

    Using a EFS volume should be the best compromise. It should not effect your cold start time too much, since the volume just has to be mounted and no files need to be downloaded. You also won't have the issue of the restricted 512MB /tmp.