36

I have an error Code storage limit exceeded deploy the serverless application in AWS. Total size 409 B.

The error message says:

An error occurred: HelloLambdaFunction - Code storage limit exceeded. (Service: AWSLambda; Status Code: 400; Error Code: CodeStorageExceededException; Request ID: ...)

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Ashish Kadam
  • 1,439
  • 2
  • 13
  • 18

6 Answers6

45

Looking specifically for this problem related to serverless, I found https://github.com/serverless/serverless/issues/400. It is a known problem of the serverless framework. However, some enterprising individual created a solution to the problem with a plugin that is able to prune old versions: https://github.com/claygregory/serverless-prune-plugin. This allows you to clean up the old versions and code storage without deleting the entire stack.

For example, you can delete all but the last 10 versions using:

sls prune -n 10

There are further options for restricting by stage or region. Even better it is possible to integrate the plugin into the deploy to automatically remove all but x versions.

I used this plugin for my current serverless project and it delivered on the promise.

Corin
  • 2,317
  • 2
  • 32
  • 47
  • Yes, it works. However, clearing the versions may take long if there are a number of functions with many versions `E:\git\serverless>sls prune -n 20` `Serverless: Prune: Querying for deployed function versions Serverless: Prune: dev-insertData has 116 additional versions published and 0 aliases, 96 versions selected for deletion Serverless: Prune: Deleting Function dev-insertData v118... Serverless: Prune: Deleting Function dev-insertData v117... . : Serverless: Prune: Deleting Function dev-insertData v23... . :` – nbs Feb 17 '20 at 08:09
  • 3
    This is true. The first prune will likely take a while if you've run out of code storage. Using the plugin it prunes with each deploy so it only ever has to clean up one version. So it is just the first prune that takes time. – Corin Feb 20 '20 at 17:32
17

From PublishVersion - AWS Lambda, CodeStorageExceededException means:

You have exceeded your maximum total code size per account.

From AWS Lambda Limits - AWS Lambda:

  • Total size of all the deployment packages that can be uploaded per region: 75 GB
  • Lambda function deployment package size (compressed .zip/.jar file): 50 MB
  • Size of code/dependencies that you can zip into a deployment package (uncompressed .zip/.jar size): 250 MB
  • Total size of environment variables set: 4 KB
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
8

As already mentioned above Total size of all the deployment packages that can be uploaded per region: 75 GB . So if we set

By default, the framework creates function versions for every deploy. This behavior is optional, and can be turned off in cases where you don't invoke past versions by their qualifier. If you would like to do this, you can invoke your functions as arn:aws:lambda:....:function/myFunc:3 to invoke version 3 for example.

To turn off this feature, set the provider-level option versionFunctions.

provider: versionFunctions: false

kartick shaw
  • 915
  • 13
  • 5
4

I am Solve that issues, to delete cloud formation stack using sls remove and deploy serverless project using sls deploy command. that's work for me.

Ashish Kadam
  • 1,439
  • 2
  • 13
  • 18
  • 8
    Deleting your stack (possibly losing data in attached resources) is dangerous and an overkill for a problem that has much safer solutions (e.g. sls prune -n 10). – Slav Apr 19 '21 at 09:58
  • definitely agree that there should be more of a disclaimer here for what this command is doing – Julian Feb 23 '22 at 18:33
3

Requesting an AWS Lambda function and layer storage quota increase and calling aws cloudformation continue-update-rollback after the request is approved should remedy stacks stuck in UPDATE_ROLLBACK_FAILED due to CodeStorageExceededException

Pat Myron
  • 4,437
  • 2
  • 20
  • 39
0

For anyone coming here (like myself) who's using Zappa and seeing this error, the solution is similar to sls prune but instead use "num_retained_versions": 10 (or whatever retained value you care for) in your zappa_settings.json. As has been mentioned, you have a certain quota of versions for your region and it's unclear when you'll hit it but when you do, it's a pain to work out the reason.

James Broad
  • 1,210
  • 12
  • 17