in lambda/share_snapshots_aurora/lambda_function.py [0:0]
def lambda_handler(event, context):
pending_snapshots = 0
client = boto3.client('rds', region_name=REGION)
response = paginate_api_call(client, 'describe_db_cluster_snapshots', 'DBClusterSnapshots', SnapshotType='manual')
filtered = get_own_snapshots_share(PATTERN, response)
# Search all snapshots for the correct tag
for snapshot_identifier,snapshot_object in filtered.items():
snapshot_arn = snapshot_object['Arn']
response_tags = client.list_tags_for_resource(
ResourceName=snapshot_arn)
if snapshot_object['Status'].lower() == 'available' and search_tag_share(response_tags):
try:
# Share snapshot with dest_account
response_modify = client.modify_db_cluster_snapshot_attribute(
DBClusterSnapshotIdentifier=snapshot_identifier,
AttributeName='restore',
ValuesToAdd=[
DEST_ACCOUNTID
]
)
except Exception as e:
logger.error('Exception sharing {}: {}'.format(snapshot_identifier, e))
pending_snapshots += 1
if pending_snapshots > 0:
log_message = 'Could not share all snapshots. Pending: %s' % pending_snapshots
logger.error(log_message)
raise SnapshotToolException(log_message)