Created
March 10, 2023 17:05
-
-
Save financial-python/02afa07439ed63ba4d831f46171fa2c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
Will need to install boto3: pip install boto3 | |
""" | |
import os | |
import boto3 | |
# variables come from AWS Management Console | |
os.environ['AWS_ACCESS_KEY_ID'] = 'YOUR_ACCESS_KEY' | |
os.environ['AWS_SECRET_ACCESS_KEY'] = 'YOUR_SECRET_KEY' | |
#create s3 client with boto3 package | |
s3 = boto3.client('s3') | |
#specify the bucket where file lives and the name of the file | |
bucket_name = 'your-bucket-name' | |
file_key = 'path/to/your/file' | |
#use the download_file() method of the S3 client to download the file to your local machine | |
#The ‘/path/to/local/file’ variable specifies where on your local machine you would want to save the file | |
s3.download_file(bucket_name, file_key, '/path/to/local/file') | |
""" | |
Alternatively, you can use the boto3.resource() method to create a boto3 resource and | |
download file using download_file method on the resource | |
""" | |
s3 = boto3.resource('s3') | |
s3.Bucket(bucket_name).download_file(file_key, '/path/to/local/file') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment