Back to 2b site

Exploring AWS Lambda: Performance and Cost Analysis of Different Architectures and Deployment Methods

In the current tech landscape, AI and cloud services are taking the lead. Companies are pushing the limits of their offerings to improve performance, reliability, and overall service quality. One of the standout services in AWS is AWS Lambda, a fully serverless compute service that lets you focus on your code without worrying about the underlying infrastructure. 

There are several ways to deploy Lambda functions, especially in the AWS Tokyo Region. You can choose between ARM64 (Graviton) or x86 architectures, and you can deploy using ECR (Elastic Container Registry) or S3 (Simple Storage Service). Each option has its own benefits and drawbacks. This post will break down these deployment methods and provide benchmarks to help you decide which is best for your needs. 

 

What’s the Goal? 

We want to use AWS Lambda to optimize our AWS services setup. The aim is to get the best performance with minimal API response latency, handle multiple parallel jobs efficiently, and keep costs low. The challenge is finding the right mix of architecture and deployment methods that balances these factors while ensuring the system remains scalable and reliable. 

 

Our Approach 

Let’s look at the demo architecture we’ll use. We’ll create four groups of Lambda functions: 

  1. CPU-intensive with long execution times 
  2. CPU-intensive with short execution times 
  3. Memory-intensive with long execution times 
  4. Memory-intensive with short execution times 

Each group will have three types of Lambda functions: 

  • ARM64 architecture using S3 for deployment 
  • x86 architecture using S3 for deployment 
  • ARM64 architecture using ECR for deployment 

This gives us 12 Lambda functions in total. We’ll run these functions simultaneously with cold starts to see the real performance and cost differences. 

 

Setting Up the Deployment 

To run the functions at the same time, we’ll use AWS Step Functions. We’ll trigger the functions every 5 minutes using AWS EventBridge. We’ll also create CloudWatch dashboards to monitor performance and costs for each group. 

 

Steps to Build the Environment 

1. Up Architecture: Understand and set up the architecture for this demo.Set Up Architecture2. Create ECR Repositories: Set up ECR repositories for the Lambda functions that will use ECR.

ECR Repositories

3. Create S3 Bucket: Set up an S3 bucket with specific paths for Lambda functions that will use S3.

Create S3 Bucket

4. Create CPU-Intensive App: Develop a CPU-intensive app in Python using Numpy.

Create CPU-Intensive App

5. Create Memory-Intensive App: Develop a memory-intensive app in Python using Pandas and Numpy.

Create Memory-Intensive App

6. Create Dockerfiles: Write Dockerfiles for Lambda functions to be deployed via ECR.

Create Dockerfiles

7. Install AWS SAM CLI: Use AWS SAM CLI to create serverless infrastructure with simple YAML templates for S3 and ECR deployments.

Install AWS SAM CLI

Install AWS SAM CLI

8. Deploy Lambda Functions: Deploy the 12 Lambda functions using AWS SAM CLI templates.

Deploy Lambda Functions

9. Set Up Step Function: Create a Step Function to trigger the Lambda functions in parallel.

Set Up Step Function

10. Configure EventBridge: Use EventBridge to trigger the Step Function every 5 minutes.

Configure EventBridge

11. Test Setup: Ensure the Step Function works and let it run for several hours to verify all executions.

Test Setup

12. Create Dashboards: Set up CloudWatch dashboards to analyze performance and cost differences.

Benchmark Analysis

Benchmark Analysis

CPU-Intensive, Long Execution

  • Performance: ARM64 (Graviton) is generally 7-9% faster than x86, with some variations.
  • Cost: ARM64 is 13-36% cheaper than x86. Deploying via S3 is generally cheaper and 1-2% faster than ECR.

CPU-Intensive, Long Execution

CPU-Intensive, Short Execution

  • Performance: ARM64 consistently outperforms x86 by 10-40%.
  • Cost: ARM64 is 30-60% cheaper. S3 deployment is 1-13% faster and cheaper than ECR.

CPU-Intensive, Short Execution

Memory-Intensive, Long Execution

  • Performance: ARM64 performs 25-35% better than x86.
  • Cost: ARM64 offers a 55-65% cost reduction. No significant difference between S3 and ECR deployments.

Memory-Intensive, Long Execution

Memory-Intensive, Short Execution

  • Performance: ARM64 is 5-25% better than x86.
  • Cost: ARM64 is 35-55% cheaper. S3 deployment is generally better.

Summary

Our benchmarks show that ARM64 Graviton instances are faster and more cost-effective than x86 instances, reflecting the growing trend towards ARM64 adoption. Many developers are already using ARM64, especially with M1 Apple computers. For deployment methods, S3 is generally faster and cheaper, though ECR is easier to automate with CI/CD using AWS SAM.