High Cold Start for AWS Lambda with Free tier account

0

Hi, I'm developing an application using AWS Lambda with a Free Tier AWS account. I have noticed that the cold start of my lambda is very high. I have optimized the code but still i have high cold start time. Is it possible that with the free tier account i have resource limitations and that's the cause to my problem? I can't find any information about the resource given with the free tier account in AWS documentation.

  • I don't have enough information to formulate an answer. How long is the cold start? How often does it occur? What are the language and libraries involved? Can you elaborate on the steps you've taken to optimize the code?

preguntada hace un año282 visualizaciones
2 Respuestas
1
Respuesta aceptada

Hi @Pasqu_96, running Java in Lambda can experience cold starts, all depends on how is developed and what is doing. Let me start from the very beginning of your question. Free tier within AWS doesn't mean cheaper infrastructure, you can use the free tier for every AWS services allocated within the same underlying infrastructure as every other AWS customer will do. AWS allocates CPU depending on the amount of memory configured, the more memory configured, the more CPU you get. What I would suggest is to play with the following.

  1. Increase the memory up to optimal performance
  2. Optimize your code if needed (specially if your are using AWS SDK)

Increase the memory up to optimal performance

The more CPU you get, the Java VM will start faster. Now, you might be wondering about the free tier, more memory means that I will exhaust the free tier faster, and that is not always true and let me explain you why.

Let's say that you have your Lambda configured with 512Mb and considering that the free tier is 400,000 GB-seconds of compute time per month. If your lambda takes 10 seconds to finish (including the cold start up to returning the result), then you consumed 5 GB-seconds out of the 400,000.

Now let's say that you have your lambda configured with 2GB You will need to measure how much time is your lambda taking from the cold start up to returning the result using Cloudwatch, but Assuming that is taking 2 seconds now, then you will be using 4 GB-seconds out of the 400,000.

Optimize your code if needed (specially if your are using AWS SDK)

Depending on what your are doing and specially if your are using the AWS SDK, please this is must watch video [1] with all the tip and tricks for you to optimize your code end to end. 100% recommended.


In summary, you can play with the amount of memory making sure that you get the correct amount of CPU/Memory combination to run cost-efficient with high performance. Then after tuning your code you can iterate to adjust the CPU Memory combination again.

I hope this information helps!

Best Practices for Lambda and Java

[1] https://youtu.be/ddg1u5HLwg8

profile pictureAWS
EXPERTO
Sercast
respondido hace un año
profile picture
EXPERTO
revisado hace 4 meses
  • thank you for the suggestions. I have tried increasing the memory assigned to my lambads and the cold start has decreased. I will try to optimize my code and use the best practice to decrease it even further

0

There shouldn't be any restriction because it is free-tier.

Cold start will depend on many factors. More details are needed to ascertain the cause.

How much time is it taking? What programming language and version are you using? What is the memory configuration given?

AWS
respondido hace un año
  • I'm developing the function using native java 20 with GraalVM and Spring Cloud Functions. I have set for each function 512MB of memory.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas