in src/sagemaker_training/intermediate_output.py [0:0]
def _upload_to_s3(s3_uploader, relative_path, file_path, filename):
"""Upload a file to S3."""
try:
key = os.path.join(s3_uploader["key_prefix"], relative_path, filename)
s3_uploader["transfer"].upload_file(file_path, s3_uploader["bucket"], key)
except FileNotFoundError: # noqa ignore=F821
# Broken link or deleted
pass
except Exception: # pylint: disable=broad-except
logger.exception("Failed to upload file to s3.")
finally:
# delete the original file
if os.path.exists(file_path):
os.remove(file_path)