cannot deploy - ERROR: You cannot have more than 500 Application Versions
You can manage lifecycle policies from the AWS console now.
In the Actions drop-down on the right hand side of the application you'd like to manage, click View application versions.
Click on the Settings button on the top right and you'll be able to configure the amount of versions you'd like to keep around:
If you have already reached the limit, you must manually first delete some versions to allow this lifecycle policy to kick in (for an explanation read the note below).
Note
From the Configuring Application Version Lifecycle Settings documentation:
Elastic Beanstalk applies an application's lifecycle policy each time you create a new application version, and deletes up to 100 versions each time the lifecycle policy is applied. Elastic Beanstalk deletes old versions after creating the new version, and does not count the new version towards the maximum number of versions defined in the policy.
Elastic Beanstalk does not delete application versions that are currently being used by an environment, or application versions deployed to environments that were terminated less than ten weeks before the policy was triggered.
The application version limit applies across all applications in a region. If you have several applications, configure each application with a lifecycle policy appropriate to avoid reaching the limit. Elastic Beanstalk only applies the policy if the application version creation succeeds, so if you have already reached the limit, you must delete some versions manually prior to creating a new version.
I find the solution here, the simple solution is to delete the previous versions as explained below.
To delete an application version
Open the Elastic Beanstalk console, and in the Regions list, select your AWS Region.
In the navigation pane, choose Applications, and then choose your application's name from the list.
Note
If you have many applications, use the search bar to filter the application list.
In the navigation pane, find your application's name and choose Application versions.
Select one or more application versions that you want to delete.
Choose Actions, then choose Delete.
(Optional) To leave the application source bundle for these application versions in your Amazon Simple Storage Service (Amazon S3) bucket, clear the box for Delete versions from Amazon S3.
Choose Delete.
Another solution
Go to version settings and enable lifecycle policy the way it is shown below.
Reference: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-versions.html
At the time of writing this answer, eb labs cleanup-versions
does not work for me: it returned No application versions to delete
even when I had application versions.
As a workaround, I used this one-liner inspired from this answer (change the region and app name accordingly):
aws elasticbeanstalk describe-application-versions --output text --region=us-west-2 --query 'ApplicationVersions[*].[ApplicationName,VersionLabel,DateCreated]' | grep my-app-name | while read app ver date; do echo "deleting version $app $ver $date" ; aws elasticbeanstalk delete-application-version --region=us-west-2 --application-name $app --version-label $ver --delete-source-bundle; done
A feature was recently added to eb cli (v3.3) to cleanup old versions
https://m.reddit.com/r/aws/comments/340ce0/whats_the_thinking_behind_beanstalks_versioning/
Copying command from reddit link
$ eb labs cleanup-versions --help
usage: eb labs cleanup-versions [options...]
Cleans up old application versions.
optional arguments:
--num-to-leave NUM number of versions to leave DEFAULT=10
--older-than DAYS delete only versions older than x days DEFAULT=60
--force don't prompt for confirmation