Skip to content
Snippets Groups Projects
Commit e79150fc authored by nimrod's avatar nimrod
Browse files

- Added TODO item of dry_run mode.

- Starting work on command arguments.
parent 1483774b
Branches
Tags
No related merge requests found
...@@ -10,4 +10,4 @@ TODO ...@@ -10,4 +10,4 @@ TODO
- Changelog. - Changelog.
- README, - README,
- Testing with different Python versions with tox and flake8. - Testing with different Python versions with tox and flake8.
- Specify number of versions to keep. - Specify number of versions to keep, dry-run option.
...@@ -6,6 +6,8 @@ from botocore import session ...@@ -6,6 +6,8 @@ from botocore import session
def main(): def main():
versions_to_keep = 400
dry_run = False
print('Pruning Elastic Beanstalk versions.') print('Pruning Elastic Beanstalk versions.')
aws_session = session.get_session() aws_session = session.get_session()
beanstalk_client = aws_session.create_client('elasticbeanstalk') beanstalk_client = aws_session.create_client('elasticbeanstalk')
...@@ -21,8 +23,10 @@ def main(): ...@@ -21,8 +23,10 @@ def main():
lambda x: (not x['VersionLabel'] in active_versions) and lambda x: (not x['VersionLabel'] in active_versions) and
x['Status'] == 'UNPROCESSED', versions) x['Status'] == 'UNPROCESSED', versions)
old_versions = sorted(previous_versions, old_versions = sorted(previous_versions,
key=lambda x: x.get('DateCreated'))[:-400] key=lambda x:
x.get('DateCreated'))[:-versions_to_keep]
for version in old_versions: for version in old_versions:
if not dry_run:
response = beanstalk_client.delete_application_version( response = beanstalk_client.delete_application_version(
ApplicationName=version['ApplicationName'], ApplicationName=version['ApplicationName'],
VersionLabel=version['VersionLabel'], VersionLabel=version['VersionLabel'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment