Understanding AWS Lambda Code Storage

Today I found out just how quickly AWS Lambda’s code storage adds up. I checked the console and saw 27 GB of code taking up space—far more than I expected. What’s counting toward that total, and how can you avoid the same surprise?

AWS Lambda console "Resources for United States (Ohio)" panel with 15 functions and 27 GB code storage (36% of 75 GB).
AWS Lambda regional dashboard showing 15 functions and 27 GB of code storage (36% of the 75 GB limit).

My 15 functions together only consume about 392 MB of code storage. You can list each function along with its package size (in bytes) using this handy one-liner:

aws lambda list-functions \
  --query 'Functions[].{Name:FunctionName,Size:CodeSize}' \
  --output table

Results:

----------------------------------------------------------------------------------
|                                  ListFunctions                                 |
+--------------------------------------------------------------------+-----------+
|                                Name                                |   Size    |
+--------------------------------------------------------------------+-----------+
|  rapid-plastic-prod-jobsWorker                                     |  49042431 |
|  rapid-plastic-dev-web                                             |  49057098 |
|  rapid-plastic-dev-artisan                                         |  49057098 |
|  rapid-plastic-ping                                                |  230      |
|  spa-deploy                                                        |  243      |
|  ses-autopauser                                                    |  465      |
|  paradox-sync-checker                                              |  683      |
|  rapid-plastic-prod-artisan                                        |  49042431 |
|  rapid-plastic-prod-cron                                           |  49042431 |
|  cwsyn-rapid-plastic-login-a-0f143ec8-d169-4f0e-9a35-79899713363b  |  1521     |
|  s3-to-mysql-table                                                 |  894506   |
|  rapid-plastic-dev-cron                                            |  49057098 |
|  trigger-syntetic-canary                                           |  491      |
|  rapid-plastic-prod-web                                            |  49042431 |
|  rapid-plastic-dev-jobsWorker                                      |  49057098 |
+--------------------------------------------------------------------+-----------+


What Counts Toward Lambda Code Storage?

For reference, Lambda code storage metric is regional and consists of (source):

  • Package size of all current functions ($LATEST)
  • Package size of each function version
  • Size of each layer
  • Size of each layer version

Ephemeral storage is not part of the metric.

I only have two layers, and their total is negligible here. The real culprit is function versions: For example, `rapid-plastic-prod-web` has 136 versions:

AWS Lambda console “Versions” tab displaying 136 versions of a function, including version numbers, descriptions, and metadata.
AWS Lambda console showing 136 published versions of a function and columns for aliases, description, last modified, and architecture.

We can check its total size with following one liner. My total is 4634670359 bytes (4.6GB) code storage for single function! You can reuse this to get the total code size for any function’s versions (just change your function name).

aws lambda list-versions-by-function \
  --function-name rapid-plastic-prod-web \
  --query 'sum(Versions[].CodeSize)' \
  --output json

How to Keep Your Storage in Check

  • Monitor the Lambda Code Storage metric in CloudWatch.
  • Clean up old versions regularly via the CLI or with automation scripts.

Read more about monitoring Lambda code storage and some best practices for managing code storage in Serverless Land.