The boto3 documentation recommend to configure key from the command line. If there anyway I can put the AWS key into the python source code? Below are the code for reference.
If you have the AWS CLI, then you can use its interactive configure command to set up your credentials and default region:
aws configure
Follow the prompts and it will generate configuration files in the correct locations for you.
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('my-bucket')
for obj in bucket.objects.all():
print(obj.key)
See under 'Method Parameters' in the official documentation;
from boto3.session import Session
session = Session(aws_access_key_id='<YOUR ACCESS KEY ID>',
aws_secret_access_key='<YOUR SECRET KEY>',
region_name='<REGION NAME>')
_s3 = session.resource("s3")
_bucket = _s3.Bucket(<BUCKET NAME>)
_bucket.download_file(Key=<KEY>, Filename=<FILENAME>)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With