Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application exceeds the maximum size allowed by AWS Lambda: after small change in the code

We are using Vapor to deploy our Laravel App to AWS Lambda.

After small change (10 lines were introduced), the deploy process via GitHub action fails with the following message:

Message: Your application exceeds the maximum size allowed by AWS Lambda.

Now we can not deploy to this env (develop). All other branches (staging, production) are fine and we can use them.

No new libraries or any big changes were introduced between the last deploy.

Deploy via Vapor CLI also fails with the same message.

Any ideas where we can search for the source of the problem?

like image 573
Anton Levitsky Avatar asked Jun 29 '20 13:06

Anton Levitsky


People also ask

What is the limitation in using Lambda in your application?

Technical Limitations The maximum time a function can run is 15 minutes, and the default timeout is 3 seconds. Obviously, this makes Lambda unsuitable for long-running workloads. The payload for each invocation of a Lambda function is limited to 6MB, and memory is limited to just under 3GB.

How do I reduce the size of a Lambda deployment package?

One of the simpler workarounds is to move the large file into Cloud Storage like S3. During the lambda runtime, download the file and continue the processing as required. In this example, we can move the mock_data. csv to S3, and update the handler function to download the file from S3 before everything else.

Is there any limit to the quantity of AWS Lambda functions that can be executed at once?

Since your code is stateless, AWS Lambda can start as many copies of your function as needed without lengthy deployment and configuration delays. There are no fundamental limits to scaling a function. AWS Lambda will dynamically allocate capacity to match the rate of incoming events.


2 Answers

Lambda deployment packages have a size limit of 50 MB. The deployment package of your dev branch is crossing that limit. That's why you get the error Your application exceeds the maximum size allowed by AWS Lambda.

If reducing the size of your deployment package is not an option, upload the package to S3 & provide the S3 URL to the Lambda function. The deployment package is allowed to have a max size of 250 MB (uncompressed) when you go the S3 route.

See my blog post for more details!

like image 55
Harish KM Avatar answered Oct 23 '22 13:10

Harish KM


You can switch to a Docker Runtime. Docker deploys can be up to 10GB.

First foreach environment, create a Docker file with the name <environment>.Dockerfile, for example production.Dockerfile for the production environment.

Then in that file put:

FROM laravelphp/vapor:php81

COPY . /var/task

Then change the "runtime" for each environment in vapor.yml to "docker".

like image 35
JPollock Avatar answered Oct 23 '22 11:10

JPollock