Serverless image processing cost: the pipeline priced end to end
Resizing images in functions looks trivially cheap per image until you count storage, egress, ephemeral disk, and the variants you generate. Here is the full pipeline cost for a real workload.
Quick answer
Processing one image in a 2048 MB Lambda taking 1.2 seconds costs about $0.000041 in duration plus $0.0000002 in requests. One million images is roughly $41 in compute. The pipeline around it costs more: S3 PUTs at $0.005 per 1,000 mean $5 per million per variant, storage at $0.023 per GB-month, and CloudFront egress at $0.085 per GB for the first 10 TB. Generating 5 variants per image at 200 KB average for 1 million images adds $25 in PUTs, $23 a month in storage, and $85 per TB served. Ephemeral storage above the free 512 MB bills $0.0000000309 per GB-second, small but real for large source files.
Image processing is the canonical serverless workload: bursty, stateless, CPU-bound, and embarrassingly parallel. It is also a workload where the function is the smallest part of the bill. Teams size the Lambda carefully and then lose several times that amount to variants they never serve and cache misses they never measure.
The compute piece
| Memory | Duration for a 4 MP resize | Cost per million images |
|---|---|---|
| 512 MB | 4,200 ms | $35.20 |
| 1024 MB | 2,100 ms | $35.20 |
| 1769 MB | 1,300 ms | $37.65 |
| 2048 MB | 1,200 ms | $40.20 |
| 3008 MB | 1,050 ms | $51.68 |
Image libraries parallelize reasonably well, so the curve keeps improving past the 1,769 MB single-vCPU threshold, but the cost turns upward once the gains flatten. Arm cuts the rate about 20 percent and modern image libraries have good Arm builds, so 1769 MB on Arm is frequently the best point on this curve at roughly $30 per million.
Storage and requests around it
Take a realistic pipeline: 1 million uploads a month, each generating 5 variants (thumbnail, small, medium, large, and a WebP alternative), averaging 200 KB per variant.
| Line | Calculation | Monthly cost |
|---|---|---|
| Lambda duration | 1M x 1.2 s x 2 GB | $40.00 |
| Lambda requests | 1M | $0.20 |
| S3 GET of source | 1M at $0.0004 per 1,000 | $0.40 |
| S3 PUT of variants | 5M at $0.005 per 1,000 | $25.00 |
| S3 storage, variants | 1,000 GB at $0.023 | $23.00 |
| S3 storage, originals | 2,000 GB at $0.023 | $46.00 |
| CloudFront egress, 5 TB | 5,000 GB at $0.085 | $425.00 |
| Total | $559.60 |
The function is 7 percent of the bill. Egress is 76 percent. That ratio is typical, and it means optimization effort spent shaving milliseconds off the resize is effort spent on the wrong thing. Serving smaller files and serving them from cache is where the money is.
Generating on demand instead of ahead of time
The pipeline above generates 5 variants for every upload regardless of whether anyone requests them. In most media libraries, a large fraction of images are never viewed at all, and of those that are, usually only one or two sizes are requested. Generating variants lazily on first request, then caching in CloudFront and writing back to S3, changes the arithmetic completely.
| Approach | Variants created per month | Compute + PUT + storage |
|---|---|---|
| Eager, all 5 variants | 5,000,000 | $88.00 |
| Lazy, 30% of images viewed, 2 sizes | 600,000 | $14.60 |
| Lazy with 90% cache hit on repeats | 600,000 | $14.60 |
Lazy generation cuts the non-egress portion by roughly 83 percent here. The cost is first-request latency, which a small placeholder or a blur-up technique usually hides. It also means your origin function must be idempotent, since concurrent requests for the same missing variant will both trigger generation.
Ephemeral storage and memory limits
Lambda includes 512 MB of ephemeral storage in /tmp free and charges $0.0000000309 per GB-second beyond it, up to 10 GB. For a 1.2 second function at 2 GB of extra ephemeral storage, that is $0.000000074 per invocation, about $0.07 per million. Negligible, but the reason to care is failure: a large TIFF or a multi-page PDF that exceeds available space fails the invocation, and a failed invocation costs its full duration plus retries. Streaming rather than buffering source files avoids both.
Where managed services change the math
Some image work is not resizing. Content moderation, label detection, and face analysis through Rekognition cost $0.001 per image for the first million images per month in most regions, which is $1,000 per million, roughly 25 times the entire Lambda resize cost. Text extraction through Textract starts at $0.0015 per page for detection. These charges dwarf everything else in the pipeline, so the design question becomes how few images you can analyze rather than how fast you can process them. Analyzing only on upload rather than on every variant, skipping analysis for images below a size threshold, and caching results by content hash are all worth far more than any compute tuning once a managed vision service is in the path.
Cutting the part that matters
Serve modern formats: WebP is typically 25 to 35 percent smaller than JPEG at equivalent quality, and AVIF more still. On 5 TB of monthly egress at $0.085 per GB, a 30 percent reduction saves $127 a month. Set long cache headers so CloudFront serves repeats without touching the origin, which removes both egress from S3 and function invocations. Use responsive sizing so phones do not download desktop images. And apply a lifecycle policy to originals, since source files that are only needed for regeneration sit well in Infrequent Access at $0.0125 per GB-month or Glacier Instant Retrieval at $0.004.
Price the whole pipeline, storage and distribution included, against theresource catalog rather than just the function, or you will optimize 7 percent of the bill.
FAQ
How much does it cost to resize an image in Lambda?
A 2048 MB function taking 1.2 seconds costs about $0.000041 in duration plus $0.0000002 in request charges, so roughly $40 per million images. On Arm at 1769 MB, where most image libraries run well, the same workload is closer to $30 per million. Memory tuning matters because image processing parallelizes past the single-vCPU threshold.
What dominates serverless image pipeline cost?
Egress. In a pipeline handling 1 million uploads a month with 5 variants each and 5 TB of delivery, CloudFront egress at $0.085 per GB is about $425 of a $560 total, roughly 76 percent, while the Lambda compute is about $40, or 7 percent. Optimizing resize duration addresses the smallest line on the bill.
Should I generate image variants eagerly or on demand?
On demand is usually much cheaper. Generating 5 variants for every upload creates 5 million variants a month for 1 million images, costing about $88 in compute, PUTs, and storage. Generating lazily when 30 percent of images are viewed at 2 sizes creates 600,000 variants for about $15, an 83 percent reduction, at the cost of first-request latency.
Does Lambda ephemeral storage cost extra for image processing?
Only above the free 512 MB in /tmp, where it bills $0.0000000309 per GB-second up to 10 GB. For a 1.2 second invocation with 2 GB extra, that is about $0.07 per million images, which is negligible. The practical concern is failure: large source files that exhaust the space fail the invocation and pay full duration plus retries.
How much does switching to WebP save?
WebP is typically 25 to 35 percent smaller than JPEG at equivalent quality. On 5 TB of monthly CloudFront egress at $0.085 per GB, a 30 percent size reduction saves about $127 a month. AVIF compresses further still. Because egress dominates the pipeline, format choice delivers larger savings than any compute-side tuning.
How does C3X help with image pipeline cost?
C3X prices functions, buckets, and distribution resources from Terraform together, so a pipeline's storage and delivery lines appear next to its compute. That reframes the optimization target correctly, showing that variant storage and egress dwarf the function, and lets you evaluate lifecycle policies and storage classes before the originals bucket has grown to terabytes.
What to do next
Price the whole pipeline, not just the function. C3X reads your Terraform and prices your resources against a live catalog. Start with the quickstart.
Share this post
Try C3X on your own Terraform
Free and open source. No API key required. One command to install, one command to estimate.