Created
August 1, 2021 12:04
-
-
Save anna-geller/07bb76b9a98d73b0f2a10b68b6fa4f1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import boto3 | |
import tempfile | |
S3_BUCKET = "annageller" | |
S3_PREFIX = "sales/" | |
with tempfile.TemporaryDirectory() as tempdir: | |
s3 = boto3.client("s3") | |
response = s3.list_objects_v2(Bucket=S3_BUCKET, Prefix=S3_PREFIX) | |
s3_objects = [obj["Key"] for obj in response["Contents"]] | |
for s3_file in s3_objects: | |
local_file_path = os.path.join(tempdir, s3_file.replace(S3_PREFIX, "")) | |
s3.download_file(S3_BUCKET, s3_file, local_file_path) | |
print(f"Downloaded files: {', '.join(os.listdir(tempdir))}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment