最近有人亲眼目睹了
TooManyApplicationVersions Exception
在AWS Elastic Beanstalk控制台上部署新的应用程序版本(战争)?看到这条消息是非常烦人的,因为它只在你完成上传战争后出现。
我很想知道为什么会发生这种异常以及应该采取哪些预防措施来避免这种情况?
您所看到的例外源于达到AWS Elastic Beanstalk的相应帐户限制,请参阅CreateApplicationVersion中的错误[释义]:
- TooManyApplicationVersions - 调用者已超出与其帐户关联的应用程序版本数量限制。
- TooManyApplications - 呼叫者已超出与其帐户关联的应用程序数量限制。
各种FAQ How many applications can I run with AWS Elastic Beanstalk?概述了目前的限制:
您最多可以创建25个应用程序和500个应用程序版本。默认情况下,您可以在所有应用程序中运行多达10个环境。如果您还在Elastic Beanstalk之外使用AWS,则可能不会[...]如果您需要更多资源,请填写AWS Elastic Beanstalk请求表单,我们会及时评估您的请求。 [强调我的]
正如所强调的那样,AWS提供了通常的升级选项,并允许您提交Request to Increase AWS Elastic Beanstalk Limits,如果您确实需要许多应用程序版本仍可供重用。否则你可能会删除不再使用的旧版本,问题应该相应消失。
祝好运!
这是一个使用AWS CLI的单线程,它将帮助您清除旧的应用程序版本:
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
用你认为合适的日期(2013,2014-01,2014-02-0等)替换grep。
从EB CLI 3.3开始,您现在可以运行以下命令来清除旧版本:
$ eb labs cleanup-versions
默认情况下,这将清除最后10个版本和/或超过60天。添加--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
这是我们在部署脚本中用于删除最早的应用程序版本的代码段。
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 + ')');
}
});
}
});
});
Elastic Beanstalk API(js)的文档:http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ElasticBeanstalk.html