You’re deploying a new version of some AWS Lambda functions, and then you get a very cryptic error from CloudFormation: “Code Storage Limit Exceeded”.
Not only does this make the deployment fail, but it also prevents rolling back.
So what’s going on? Most likely you’ve hit the 75 GiB code storage limit; the AWS Lambda dashboard should be displaying a warning to confirm this.
How is this possible? Well, Lambda functions have
versions. And when you deploy a Lambda function, it creates a new version.
You may not know this, because it’s simply called
$LATEST. Also, AWS
doesn’t call it “version” in the GUI, but “qualifier”
(this is because it includes aliases).
How do you fix this? It’s easy in principle, delete the old Lambda function
versions. However, doing this in the web UI is extremely tedious. So here’s a
script to delete all the versions except
$LATEST. Don’t use it if you have
published any other versions/aliases, and - as always - this is an example
script with no warranty.