in Lambda/TagOnRestore/src/TagOnRestore.py [0:0]
def __set_tags_by_resource(self, resource_type, resource_id, resource_arn, tag_list):
"""
Helper function to set the tags on a given resource.
"""
resource_type = resource_type.lower()
logger.info(f"Processing __set_tags_by_resource with resource_type: {resource_type}, " +
f"resource_arn : {resource_arn},resource_id : {resource_id}, tag_list : {tag_list}" +
f"tag exclusions : {self.tags_to_exclude_when_copying}")
for tag_info in tag_list:
if tag_info['Key'] in self.tags_to_exclude_when_copying:
tag_list.remove(tag_info)
if resource_type == 'dynamodb':
dynamo_client = boto3.client('dynamodb')
dynamo_client.tag_resource(ResourceArn=resource_arn, Tags=tag_list)
elif resource_type in ('ec2', 'ebs'):
ec2_client = boto3.client('ec2')
ec2_client.create_tags(DryRun=False, Resources=[resource_id], Tags=tag_list)
elif resource_type in ('rds', 'aurora'):
rds_client = boto3.client('rds')
rds_client.add_tags_to_resource(ResourceName=resource_id, Tags=tag_list)
elif resource_type == 'fsx':
fsx_client = boto3.client('fsx')
fsx_client.tag_resource(ResourceARN=resource_arn, Tags=tag_list)
elif resource_type == 'storagegateway':
storagegateway_client = boto3.client('storagegateway')
storagegateway_client.add_tags_to_resource(ResourceARN=resource_arn,
Tags=tag_list)
elif resource_type in ('elasticfilesystem', 'efs'):
efs_client = boto3.client('efs')
efs_client.create_tags(FileSystemId=resource_id, Tags=tag_list)
else:
logger.info(f"{resource_type} Not Supported Yet, Fetchable from backup")