def s3_download_file()

in app/source/dragen/src/scheduler/aws_utils.py [0:0]


def s3_download_file(req_info, nosign=False):
    # If region is missing fill in default
    if not req_info['region']:
        req_info['region'] = 'us-east-1'

    # Configure the download
    if nosign:
        client = boto3.client('s3', req_info['region'], config=Config(signature_version=UNSIGNED))
    else:
        client = boto3.client('s3', req_info['region'])

    # Make sure the target directory exists
    tgt_dir = req_info['tgt_path'].rsplit('/', 1)[0]  # get the directory part
    utils.check_create_dir(tgt_dir)

    # Check if the object already exists locally and get the size on disk
    if os.path.exists(req_info['tgt_path']):
        loc_size = os.path.getsize(req_info['tgt_path'])
        # Check if the S3 object length matches the local file size
        obj_info = s3_get_object_info(req_info['bucket'], req_info['obj_key'])
        if obj_info['ContentLength'] == loc_size:
            return loc_size

    # Perform the download
    transfer = S3Transfer(client)
    transfer.download_file(req_info['bucket'], req_info['obj_key'], req_info['tgt_path'])

    # Once download is complete, get the file info to check the size
    return os.path.getsize(req_info['tgt_path'])