Guidelines for Production Ready AWS Lambda

Posted By : Abhishek Gupta | 30-Aug-2022

AWS Lambda Best Practices


Guidelines for Production Ready AWS Lambda


Best Practices of AWS Lambda which you can consider while building Production Ready Lambda's.

1. Provisioned Concurrency

Initializes a requested number of Lambdas, ready to serve requests 

Fix Cold Start issues

You can implement auto-scaling with Provisioned Concurrency also:

  • During Day time, 10 instances
  • During night, 2 instances

Note that configuring provisioned concurrency leads to incurs charges to your AWS account.

2. Avoid Spring Boot

Two main reasons:

  • Spring Boot start-up times
  • Un-necessary libraries that Spring Boot adds

If using Spring For DI(dependency injection)

  • Use Dagger/Guice DI libraries 

3. Avoid Lambda Chaining

Lambda Chaining happens when you call one lambda function from another so this a very famous anti-pattern even listed in aws official Documents.

Problem with this Flow :

  • Cost
  • Error Handling 
  • Tight Coupling
  • Scaling

How to Avoid :

  • Step Function
  • SQS

4. Artifact Size

Minimize deployment package size

Deployment size matter because of two reasons 

  • Limitation of the platform 

Direct Upload(zip/jar) : 50MB

Unzipped(including layers) :250MB

  • Cold Start

Solution

  • Don’t load the entire AWS SDK, Only use the dependencies that are required. Eg DynamoDB, S3
  • Only use the required dependencies 

5. Build an Idempotent Lambda

Idempotent :  “The property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result beyond the initial application” impotence is a very important aspect of serverless.

How to achieve :

  • Use DynamoDB Upsert 
  • PowerTools Idempotency

 

6. Monitor all important metrics with CloudWatch metrics

serverless applications produce a set of standard metrics that will help you understand the performance and availability of your system

  • Throttles
  • Errors
  • Invocations
  • Duration

Source: https://aws.amazon.com/lambda/

About Author

Author Image
Abhishek Gupta

Abhishek Gupta is a skilled Backend developer with 1.4 years of industry experience. He has a deep understanding and knowledge of the latest technologies, including Core Java, J2EE, Spring-Boot, Spring Security, Hibernate, Cloud, MySQL, MongoDB, and Microservices. His expertise lies in gathering requirements from the functional team, analyzing, designing, and developing projects. He has made significant contributions to the success of various internal projects, Oodles Dashboard. He remains committed to enhancing his skills and knowledge by constantly learning and staying updated with the latest programming techniques and technologies.

Request for Proposal

Name is required

Comment is required

Sending message..