AWS Lambda : Zip or Docker image ?

A common decision I had to make those past years was to make a choice between zip files or docker images as code deliverables for AWS Lambda functions. I’ll share with you some hints about AWS Lambda that could help you taking the right decision in the…


This content originally appeared on DEV Community and was authored by Meidi Airouche

A common decision I had to make those past years was to make a choice between zip files or docker images as code deliverables for AWS Lambda functions. I'll share with you some hints about AWS Lambda that could help you taking the right decision in the right context.

AWS Lambda : reminder about how it works

Lambda functions are stateless compute services that execute code. it can be invoked, croned, react to events... To upload you code into those lambda functions, there are many ways to do it. 2 main ways are :

  • Push a zip file with code and dependencies
  • Pull a docker image with code and dependencies

Many organisations have now integrated Docker images as their goto delivery format. Moreover, most of them have built their CI/CD around this format and want to keep the same for delivering AWS Lambdas.

So, is it a good idea ?

Performance considerations

When it comes to AWS Lambdas, you may have heard about Cold and Warm start.

Performances

  • Cold start : the time required for the Lambda to download your code and make the underlying infrastructure ready to run.
  • Warm start : the time required for your code to be runned.

So, the first time a lambda is called, cold + warm start will occur. AWS will keep this underlying infrastructure up for a non-deterministic amount of time to improve resource management and performance. That's why, if the same lambda is called again during this period, there is only a warm start and no cold start.

That's why many people use function warmers with EventBridge (cron awaking the function periodically to make it warm for business) or play with the provisionned cocnurrency to have a pool of warmed up functions.

How does Zip or Docker image affect lambda performances

Here is an illustration of start times between zipped code by language and docker analysis made by Mikhail Shilkov.

Languages

First, we can see that whatever the language you code with, Docker images are slower to load than zipped code. It can take 0,6 to 1,4 sec for a containerized lambda to load against around 700ms for a zip.

Why is that ?

Unzipping a ready to load folder, even a big one, is way faster than pulling an image from a registry and starting it.

How do I choose between both ?

Performances is not the only considerations you have to take in consideration when you have to choose between zip or docker for AWS Lambda functions. The tools, the competencies inside your organization is also very important. The ability to deliver properly. The end to end cost including the modifications you will have to make around CI/CD to integrate one or another...

Here are some guidelines to help taking the right decisions. It must be challenged by your other constraints :

  • When it comes to synchronous scenarios, I highly recommend to use warmers to avoid cold starts and to use zip files deliverables for your AWS lambdas. Because, having around 1sec of load in such scenarios is not acceptable in a user experience perspective.
  • When it comes to asynchronous scenarios, I would recommend to choose what seems the best for you regarding the skills of your teams, your existing CI/CD etc...

Conclusion

Of course, choosing between zip files and container images delivery for AWS lambda functions cannot be resumed only by the guidelines in this article. But, taking it in consideration in addition to your other constraints is important to obtain a completly informed opinion.


This content originally appeared on DEV Community and was authored by Meidi Airouche


Print Share Comment Cite Upload Translate Updates
APA

Meidi Airouche | Sciencx (2024-07-25T14:12:12+00:00) AWS Lambda : Zip or Docker image ?. Retrieved from https://www.scien.cx/2024/07/25/aws-lambda-zip-or-docker-image/

MLA
" » AWS Lambda : Zip or Docker image ?." Meidi Airouche | Sciencx - Thursday July 25, 2024, https://www.scien.cx/2024/07/25/aws-lambda-zip-or-docker-image/
HARVARD
Meidi Airouche | Sciencx Thursday July 25, 2024 » AWS Lambda : Zip or Docker image ?., viewed ,<https://www.scien.cx/2024/07/25/aws-lambda-zip-or-docker-image/>
VANCOUVER
Meidi Airouche | Sciencx - » AWS Lambda : Zip or Docker image ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/25/aws-lambda-zip-or-docker-image/
CHICAGO
" » AWS Lambda : Zip or Docker image ?." Meidi Airouche | Sciencx - Accessed . https://www.scien.cx/2024/07/25/aws-lambda-zip-or-docker-image/
IEEE
" » AWS Lambda : Zip or Docker image ?." Meidi Airouche | Sciencx [Online]. Available: https://www.scien.cx/2024/07/25/aws-lambda-zip-or-docker-image/. [Accessed: ]
rf:citation
» AWS Lambda : Zip or Docker image ? | Meidi Airouche | Sciencx | https://www.scien.cx/2024/07/25/aws-lambda-zip-or-docker-image/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.