Although this might be an old question, I've faced the same issue and struggled to find a solution. I tried using two Serverless Framework plugins, serverless-prune-plugin and serverless-prune-versions, but neither worked for me.
Ultimately, I resolved it by creating a script that deletes older Lambda versions, keeping only the 5 most recent ones. You can find the script here: https://github.com/jperocho/lver. Note that this script currently works only within the Serverless YAML file.
After running the script, I used the following CLI command to continue the CloudFormation rollback:
$ aws cloudformation continue-update-rollback --stack-name <your_stack_name>
Then, I retried building, and it worked.
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... . :
– Dwightdwindle