5 Tips to Optimize Your AWS Lambda Performance

2 min read Original article ↗

Deep Mistry

So, you’ve decided to embrace the serverless trend. You’re excited as you bid adieu to your ECS cluster chores forever. You go through the challenging process of migrating your application to serverless. You think you’re almost there and can see the light at the end of the tunnel. But you run your performance test and see that while your lambda does scale, response time is getting longer than expected, and you start seeing errors in your logs. You’re stumped! This was supposed to be easy! It turns out it actually is; there are but a few parameters to keep in mind when tuning your lambdas. But before we dive into them, we need to know how lambdas actually work.

How Do Lambdas Work?

Lambdas are essentially function instances that are invoked by an event trigger. Each Lambda consists of two logical execution blocks:

  1. Setup Phase — This is where the execution environment is created
  2. Work Phase — This is where the actual work is performed (handler function)

The execution environment is used for executing the handler function. Once a lambda is executed, the environment remains active for some time and may be reused for another event.

To optimize a Lambda function, we need to consider five parameters that affect Lambda performance:

  • Execution Duration — Average duration of execution of your function
  • Average TPS —Average number of requests coming in…