Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cloudformation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ Resources:
Role: !GetAtt LambdaExecutionRole.Arn
CodeUri: 'lambda'
Events:
HourlyBackupEvent:
Type: Schedule
Properties:
Schedule: rate(1 hour)
Input:
Fn::Join:
- ''
- - '{"period_label": "hour", "period_format": "%a%H-%M", "keep_count": 168,'
- '"arn": "'
- !If [EnableSuccessSNSTopic, !If [ CreateSuccessSNSTopic, Ref: SuccessSNSTopic, Ref: SuccessSNSTopicOption], '']
- '", '
- '"error_arn": "'
- !If [EnableErrorSNSTopic, !If [ CreateErrorSNSTopic, Ref: ErrorSNSTopic, Ref: ErrorSNSTopicOption], '']
- '", '
- '"ec2_region_name": "'
- Ref: AWS::Region
- '", '
- '"rds_region_name": "'
- Ref: AWS::Region
- '", '
- '"tag_name": "MakeSnapshot", "tag_value": "True" }'
DailyBackupEvent:
Type: Schedule
Properties:
Expand Down
11 changes: 7 additions & 4 deletions lambda/backuplambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ def lookup_period_prefix(self):

def get_resource_tags(self, resource):
resource_id = self.resolve_backupable_id(resource)
resource_type = 'cluster'
if 'DBClusterIdentifier' not in resource:
resource_type = 'db'

resource_tags = {}
if resource_id:
arn = self.build_arn_for_id(resource_id)
arn = self.build_arn_for_id(resource_id, resource_type)
tags = self.conn.list_tags_for_resource(ResourceName=arn)['TagList']

for tag in tags:
Expand Down Expand Up @@ -393,13 +397,12 @@ def resolve_account_number(self):
def build_arn(self, instance):
return self.build_arn_for_id(instance['DBInstanceIdentifier'])

def build_arn_for_id(self, instance_id):
def build_arn_for_id(self, instance_id, resource_type = 'db'):
# "arn:aws:rds:<region>:<account number>:<resourcetype>:<name>"

region = self.conn.meta.region_name
account_number = self.resolve_account_number()

return "arn:aws:rds:{0}:{1}:db:{2}".format(region, account_number, instance_id)
return "arn:aws:rds:{0}:{1}:{2}:{3}".format(region, account_number, resource_type, instance_id)


def lambda_handler(event, context={}):
Expand Down