diff --git a/cloudformation.yaml b/cloudformation.yaml index e577ba3..8075ce7 100644 --- a/cloudformation.yaml +++ b/cloudformation.yaml @@ -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: diff --git a/lambda/backuplambda.py b/lambda/backuplambda.py index 6d1c08d..2dfac75 100755 --- a/lambda/backuplambda.py +++ b/lambda/backuplambda.py @@ -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: @@ -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 = 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={}):