Skip to content

Instantly share code, notes, and snippets.

@anna-geller
Created August 1, 2021 12:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anna-geller/07bb76b9a98d73b0f2a10b68b6fa4f1b to your computer and use it in GitHub Desktop.
Save anna-geller/07bb76b9a98d73b0f2a10b68b6fa4f1b to your computer and use it in GitHub Desktop.
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