Skip to content

Instantly share code, notes, and snippets.

@piercelamb
Created December 19, 2022 20:28
Show Gist options
  • Save piercelamb/046fa2adf42c89296681bf62adf8eb00 to your computer and use it in GitHub Desktop.
Save piercelamb/046fa2adf42c89296681bf62adf8eb00 to your computer and use it in GitHub Desktop.
copy_to_s3
def copy_to_s3(
bucket: Bucket,
files_to_copy: List[str],
row: NamedTuple,
s3_artifact_path: str,
process_func: Optional[Callable[[str, List, str, bool], None]]=None,
reload: bool=False
):
guid = row.file_location
for s3_key in files_to_copy:
file_name = s3_key.split('/')[-1]
copy_source = {
'Bucket': "<your-prod-s3-bucket>",
'Key': s3_key
}
new_s3_key = f”{s3_artifact_path}{guid}/{file_name})”
bucket.copy(copy_source, new_s3_key)
if process_func:
guid_prefix = f”{s3_artifact_path}{guid}”
existing_files = list(bucket.objects.filter(Prefix=guid_prefix))
process_func(row, existing_files, s3_artifact_path, reload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment