Skip to content

Commit

Permalink
Replace AMIDeleteOn tag with DeleteOn tag (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetOps authored and const-bon committed Sep 20, 2017
1 parent 1bace64 commit c23dea2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ami_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# "retention_days" is environment variable which will be used as a retention policy number in days. If there is no
# environment variable with that name, it will use a 14 days default value for each AMI.
#
# After creating the AMI it creates a "AMIDeleteOn" tag on the AMI indicating when
# it will be deleted using the Retention value and another Lambda function
# After creating the AMI it creates a "DeleteOn" tag on the AMI indicating when
# it will be deleted using the Retention value and another Lambda function

from __future__ import print_function
import boto3
Expand Down Expand Up @@ -44,8 +44,8 @@ def lambda_handler(event, context):
delete_fmt = delete_date.strftime('%m-%d-%Y')

ec.create_tags(
Resources=[ec2_instance_id, AMIid['ImageId']],
Resources=[AMIid['ImageId']],
Tags=[
{'Key': 'AMIDeleteOn', 'Value': delete_fmt},
{'Key': 'DeleteOn', 'Value': delete_fmt},
]
)
8 changes: 4 additions & 4 deletions ami_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# @author Robert Kozora <bobby@kozora.me>
#
# This script will search for all AMIs having a tag with "AMIDeleteOn"
# This script will search for all AMIs having a tag with "DeleteOn"
# on it. As soon as we have the AMIs list, we loop through each images
# and reference the AMIs. We check that the latest daily backup
# succeeded then we store every image that's reached its DeleteOn tag's date for
Expand All @@ -20,7 +20,7 @@
ec = boto3.client('ec2', os.environ['region'])
ec2 = boto3.resource('ec2', os.environ['region'])
images = ec2.images.filter(Owners=[os.environ['ami_owner']],
Filters=[{'Name': 'tag-key', 'Values': ['AMIDeleteOn']}])
Filters=[{'Name': 'tag-key', 'Values': ['DeleteOn']}])

label_id = os.environ['label_id']
instance_id = os.environ['instance_id']
Expand All @@ -43,7 +43,7 @@ def lambda_handler(event, context):
if image.tags is not None:
deletion_date = [
t.get('Value') for t in image.tags
if t['Key'] == 'AMIDeleteOn'][0]
if t['Key'] == 'DeleteOn'][0]
delete_date = time.strptime(deletion_date, "%m-%d-%Y")
except IndexError:
deletion_date = False
Expand All @@ -57,7 +57,7 @@ def lambda_handler(event, context):
if image.tags is not None:
deletion_date = [
t.get('Value') for t in image.tags
if t['Key'] == 'AMIDeleteOn'][0]
if t['Key'] == 'DeleteOn'][0]
delete_date = time.strptime(deletion_date, "%m-%d-%Y")
except IndexError:
deletion_date = False
Expand Down

0 comments on commit c23dea2

Please sign in to comment.