A Null Pointer
A Null Pointer

Reputation: 2277

How to avoid a TooManyApplicationVersion exception on AWS Elastic Beanstalk?

Lately has anyone witnessed the

TooManyApplicationVersions Exception

on AWS Elastic Beanstalk console while deploying a new application version (war)? It's so annoying to see this message as it appears only after you have finished uploading the war.

I would be interested to know why this exception occurs and what precautions one should take to avoid such situations?

Upvotes: 29

Views: 15139

Answers (6)

JRichardsz
JRichardsz

Reputation: 16544

In my case:

>> The error only occurred with specific environments and/or applications. Other apps had no problems with the deploy.

>> I did not exceed the default bean stalk quotas. I validated it by counting them and comparing with the default values

environments count

aws elasticbeanstalk describe-environments --output text --query 'Environments[*].[EnvironmentName]' | wc -l

versions count

aws elasticbeanstalk describe-application-versions --output text --query 'ApplicationVersions[*].[ApplicationName]'  | wc -l

default values

enter image description here

>> I also implemented an automated recycle like update-application-resource-lifecycle

>> I deleted several environments/versions but the error persisted


If you reach this line the only solution for me was to delete manually the environment and its versions. In my case the environment had only one version.

enter image description here

Upvotes: 0

inmyth
inmyth

Reputation: 9070

You're approaching maximum number of versions and need to delete old or unused ones.

In the current web console you can simply do it on the Application Versions tab of your Beanstalk environment.

enter image description here

Upvotes: 13

Darren Shewry
Darren Shewry

Reputation: 10420

As of EB CLI 3.3, you can now run the following to clear out old versions:

$ eb labs cleanup-versions

By default this will cleanup to the last 10 versions and/or older than 60 days. Adding --help, outputs the following:

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

Upvotes: 15

null
null

Reputation: 4370

This is the piece of code that we use in our deploy script to delete the oldest application version.

console.log('Deleting oldest application version.');
params = {};
local.waitFor(function(done) {
    eb.describeApplicationVersions(params, function(err, data) {
        if (err) {
            console.error(err, err.stack);
            local.abort('Could not retrieve the list of application version.');
        } else {
            // This is probably not needed as the list is already sorted but it is
            // not written anywhere that this will always be the case
            function compare(a,b) {
                if (a.DateCreated > b.DateCreated)
                    return -1;
                if (a.DateCreated < b.DateCreated)
                    return 1;
                return 0;
            }
            var applicationsVersion = data['ApplicationVersions'].sort(compare),
                oldestApplication   = applicationsVersion[applicationsVersion.length - 1],
                applicationName     = oldestApplication['ApplicationName'],
                versionLabel        = oldestApplication['VersionLabel'];
            params = {
                ApplicationName: applicationName, /* required */
                VersionLabel:    versionLabel,    /* required */
                DeleteSourceBundle: false /* Do not delete source bundle from S3 */
            };
            eb.deleteApplicationVersion(params, function(err, data) {
                if (err) {
                    console.error(err, err.stack);
                    local.abort('Could not delete the oldest application version. (' + versionLabel + ')')
                } else {
                    console.log('Successfully deleted the oldest application version. (' + versionLabel + ')');
                }
            });
        }
    });
});

Documentation for the Elastic Beantalk API (js): http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ElasticBeanstalk.html

Upvotes: 1

tomberek
tomberek

Reputation: 319

Here's a one liner that uses the AWS CLI that will help you clear out old application versions:

aws elasticbeanstalk describe-application-versions --output text --query 'ApplicationVersions[*].[ApplicationName,VersionLabel,DateCreated]' | grep "2014-02" | while read app ver date; do aws elasticbeanstalk delete-application-version --application-name $app --version-label $ver --delete-source-bundle; done

Replace the grep with whatever date, (2013, 2014-01, 2014-02-0, etc) you see fit.

Upvotes: 21

Steffen Opel
Steffen Opel

Reputation: 64751

Cause

The exception you are seeing stems from reaching your respective account limits for AWS Elastic Beanstalk, see section Errors in CreateApplicationVersion [paraphrased]:

  • TooManyApplicationVersions - The caller has exceeded the limit on the number of application versions associated with their account.
  • TooManyApplications - The caller has exceeded the limit on the number of applications associated with their account.

The current limits are outlined in the respective FAQ How many applications can I run with AWS Elastic Beanstalk?:

You can create up to 25 applications and 500 application versions. By default you can run up to 10 environments across all of your applications. If you are also using AWS outside of Elastic Beanstalk, you may not be [...] If you need more resources, complete the AWS Elastic Beanstalk request form and your request will be promptly evaluated. [emphasis mine]

Solution

As emphasized, AWS offers the usual escalation option and allows you to submit a Request to Increase AWS Elastic Beanstalk Limits, if you really need that many application versions to be available for reuse still. Otherwise you might just delete older ones you will not use anymore and the problem should vanish accordingly.

Good luck!

Upvotes: 30

Related Questions