Skip to content

Commit f0810cb

Browse files
authored
Add capability to download file from s3 (#826)
* add capability to download file from s3 * fix flake8 error
1 parent f47421d commit f0810cb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

python/lib/aws_s3.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,22 @@ def check_if_file_key_exists_in_bucket(self, file_key):
7777
return False
7878

7979
return True
80+
81+
def download_file(self, s3_object_name, destination_file):
82+
"""
83+
Download a file from an S3 bucket
84+
85+
:param s3_object_name: S3 object name to download from
86+
:type s3_object_name: str
87+
:param destination_file: Full path where the file should be downloaded
88+
:type destination_file: str
89+
"""
90+
91+
s3_prefix = f"s3://{self.bucket_name}/"
92+
s3_file_name = s3_object_name[len(s3_prefix):] if s3_object_name.startswith(s3_prefix) else s3_object_name
93+
94+
try:
95+
print(f"Downloading {s3_file_name} from {self.aws_endpoint_url}/{self.bucket_name} to {destination_file}")
96+
self.s3_bucket_obj.download_file(s3_file_name, destination_file)
97+
except ClientError as err:
98+
raise Exception(f"{s3_object_name} download failure = {format(err)}")

0 commit comments

Comments
 (0)