Reducing Cold start, Optimizing AWS lambda.
In application that uses lambda for computation, we need to make lambda initialization and execution fast for faster response but cold start that when lambda is invoked for a first time will slow downs our application.In this blog here are the step i took to reduce cold start.
To reduce loading time of code in lambda just load the necessary service instead loading whole aws-sdk.
Memory and profiling:
Keeping in the mind "Memory is power for Lambda", we use AWS lambda Power tuning tool. Power tuning use a step function which is a state machine in which we provide lambda arn and json payload as in put and we get the result in graph. From graph we can trade-offs of cost and speed like below.
for implementing power tuning we host power tuning tool in our AWS account. here is link of GitHub how to do it https://github.com/mattymoomoo/aws-power-tuner-ui . More about power tuning tool you can find here https://github.com/alexcasalboni/aws-lambda-power-tuning .
For our purpose we have similar pattern reading and writing from DynamoDB so most of case 1024 MB is best for our need.