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:
- Timeout utilization under 20% (using under 20% of allocated execution time)
- Memory allocation 1024MB or higher (high-memory functions worth optimizing)
- Above 1000 invocations monthly (statistical significance)
- Monthly cost above $10 (meaningful savings potential)
- 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