CircleCIからElasticBeanstalkへ自動デプロイしていると、
そのうちTooManyApplicationVersionsExceptionというエラーが出てしまうという
問題に対応したので、その備忘録
awsの管理コンソールでもライフサイクルを決めることができるのに
なぜそれで対応できないのか…というのはおいておいて
shell scriptで
REGION=【region】
APP_NAME=【application name】
ENABLE_APPLICATION_COUNT=+200
aws elasticbeanstalk describe-application-versions --output text --region=$REGION --query 'ApplicationVersions[*].[ApplicationName,VersionLabel,DateCreated]' \
| grep $APP_NAME \
| tail -n $ENABLE_APPLICATION_COUNT \
| while read app ver date;
do
echo "deleting version $app $ver $date";
aws elasticbeanstalk delete-application-version --region=$REGION --application-name $app --version-label $ver --delete-source-bundle;
sleep 1
done
こんな感じでregion
application name
を設定すれば
最新200アプリケーションを残して、あとは自動削除をしてくれる