Created
September 13, 2018 18:29
-
-
Save egeloen/6fb87773a6e0b548b02a0394f4d4851a to your computer and use it in GitHub Desktop.
AWS Lambda AMI Cleaner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from amicleaner.cli import App as Cleaner | |
from amicleaner.utils import parse_args | |
# AWS Lambda AMI Cleaner | |
class AmiCleaner: | |
# Initialize the AMI Cleaner | |
def __init__(self, cleaner=None): | |
# Initialize the AMI Cleaner | |
self.cleaner = cleaner or Cleaner(parse_args([ | |
'--keep-previous', '3', | |
'--mapping-key', 'tags', | |
'--mapping-values', 'Name' | |
])) | |
# Clean AMIs | |
def clean(self): | |
# Resolve AMIs | |
amis = self.cleaner.prepare_candidates() | |
# Delete AMIs | |
if amis: | |
self.cleaner.prepare_delete_amis(amis) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cleaner import AmiCleaner | |
# AWS Lambda AMI Cleaner Handler | |
def handle(event, context, cleaner=None): | |
# Clean AMIs | |
AmiCleaner(cleaner).clean() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws-amicleaner==0.2.2 | |
future==0.16.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment