Technical Guide

Oversized Lambda Functions

How to identify over-provisioned Lambda functions? Lambda functions using under 20% of timeout duration with memory 1024MB or higher are over-provisioned and can save 30-70% on execution costs through rightsizing.

2 min read
High impact optimization

Why This Matters

Lambda pricing is based on memory allocation and execution duration, not actual usage. Over-allocating memory means paying for compute you're not using. Many functions are conservatively sized during development but never optimized for production workloads.

Common causes:

  • Conservative memory allocation without performance testing
  • Functions that started small but grew in complexity
  • Over-provisioning to avoid cold start issues
  • Legacy functions not optimized for current workloads

How to Identify Oversized Functions

AWS Saver flags Lambda functions as over-provisioned when they meet these criteria:

  1. Timeout utilization under 20% (using under 20% of allocated execution time)
  2. Memory allocation 1024MB or higher (high-memory functions worth optimizing)
  3. Above 1000 invocations monthly (statistical significance)
  4. Monthly cost above $10 (meaningful savings potential)
  5. Functions running above 10 seconds are flagged for potential container migration

How to Fix Oversized Lambda Functions

Step 1: List all Lambda functions with memory and timeout

aws lambda list-functions \
  --query 'Functions[].{Name:FunctionName,Memory:MemorySize,Timeout:Timeout}'

Step 2: Get detailed function configuration

aws lambda get-function-configuration --function-name your-function-name

Step 3: Check invocation count over 30 days

aws cloudwatch get-metric-statistics \
  --namespace AWS/Lambda \
  --metric-name Invocations \
  --dimensions Name=FunctionName,Value=your-function-name \
  --statistics Sum \
  --start-time $(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 86400

Step 4: Get average duration metrics

aws cloudwatch get-metric-statistics \
  --namespace AWS/Lambda \
  --metric-name Duration \
  --dimensions Name=FunctionName,Value=your-function-name \
  --statistics Average \
  --start-time $(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 86400

Step 5: Update function memory allocation

aws lambda update-function-configuration \
  --function-name your-function-name \
  --memory-size 512

Prevention Tips

Start with minimal memory: Begin with 128MB and scale up based on actual performance needs, not estimates.

Use Lambda Power Tuning: Leverage AWS Lambda Power Tuning tool to find optimal memory/cost balance.

Monitor regularly: Set up CloudWatch alarms for duration vs timeout ratio to catch over-provisioning.

Consider Graviton2: Use ARM-based processors (Graviton2) for up to 34% better price-performance.

Automation Available

Skip the manual work. AWS Saver automatically analyzes Lambda functions using the same timeout and memory thresholds.

Timeout utilization analysis - Identifies functions using less than 20% of allocated execution time

Memory optimization detection - Flags over-provisioned functions with 512MB+ memory

Cost impact calculation - Shows potential monthly savings from rightsizing

Long-running function alerts - Recommends container alternatives for functions over 10s

Ready to Optimize Your AWS Costs?

Skip the manual work. Get automated Lambda optimization across your entire AWS infrastructure.

60-second setup • No credit card required • Immediate results

Automation Available

Skip the manual work. AWS Saver automatically detects and prioritizes this issue across your entire AWS infrastructure.

60-second setup • No credit card required

Manual vs Automated

Manual Process

  • • Run commands across all regions
  • • Set up monitoring and alerts
  • • Repeat regularly for new issues
  • • Scale across multiple accounts

AWS Saver Automation

  • • Continuous multi-region scanning
  • • Automatic cost impact analysis
  • • Real-time alerts and notifications
  • • Cross-account visibility