in ml_ops/visualization_blog/lambdas/updateresources/update.py [0:0]
def lambda_handler(event, context):
outdated_objects = S3_CLI.list_objects_v2(
Bucket=event['bucket'], Prefix='quicksight'
)
new_objects = S3_CLI.list_objects_v2(Bucket=event['bucket'], Prefix='tmp/')
bucket = S3.Bucket(event['bucket'])
if 'Contents' in outdated_objects.keys():
for key in [obj['Key'] for obj in outdated_objects['Contents']]:
move_object(
bucket=event['bucket'],
source=key,
destination='history/clean/{}'.format(key.split('/')[1])
)
if 'Contents' in new_objects.keys():
for page, key in enumerate([obj['Key'] for obj in new_objects['Contents']]):
if re.match('^.*\.(csv|CSV)', key):
transform(
bucket.Object(key=key),
bucket=event['bucket'],
key='format_{}'.format(key),
params=event['params'],
page=page
)
move_object(
bucket=event['bucket'],
source='format_{}'.format(key),
destination='quicksight/{}'.format(key.split('/')[1])
)
move_object(
bucket=event['bucket'],
source=key,
destination='history/raw/{}'.format(key.split('/')[1])
)
return event