in src/s3_helper.py [0:0]
def s3_download_file(bucket_name, input_file_name, output_file_name, session=None):
"""Download a file from S3 to disk
Args:
bucket_name (str): Name of the bucket
input_file_name (str): Name of the file to download from S3 (including path if necessary)
output_file_name (str): Path to where the file should be downloaded to including its name
session (object, optional): boto3 session object
Returns:
dict: Standard AWS response dict
"""
logger.debug(f"bucket_name:{bucket_name}")
logger.debug(f"input_file_name:{input_file_name}")
logger.debug(f"output_file_name:{output_file_name}")
logger.debug(f"session:{session}")
tries = 3
count = 1
client = boto3_client(service='s3', session=session)
while True:
try:
logger.info(f"Attempt {count} of {tries} to download file {input_file_name} from {bucket_name}")
response = client.download_file(bucket_name, input_file_name, output_file_name)
return response
except Exception as e:
count += 1
time.sleep(10)
if count > tries:
raise Exception(
f"Failed to download key {input_file_name} in bucket {bucket_name}: {str(e)}"
) from e