import boto3
import os
S3_Object = boto3.client('s3', region_name='us-west-1' aws_access_key_id='access_key', aws_secret_access_key='secret_access_key')
s3 = boto3.resource('s3')
bucket = 'bucket_name'
#response = s3.Bucket(bucket).objects.all()
# If you want to search only specific path of bucket,
response = s3.Bucket(bucket).objects.filter(Prefix='folder_name')
path = '/tmp/logs'
if not os.path.exists(path):
os.makedirs(path)
for item in response:
filename = item.key.rsplit('/', 1)[-1]
if filename.endswith('.csv.gz'):
s3.Object(bucket, item.key).download_file(path + filename)
print("success")
我遇到以下错误
raise NoCredentialsError
botocore.exceptions.NoCredentialsError: Unable to locate credentials
所以我已经更新了.aws/config
和.aws/credentials
在.aws/config
上:
[profile 1]
region=us-west-1
在.aws/credentials
上:
aws_access_key_id='access_key'
aws_secret_access_key='secret_access_key'
没有运气。任何帮助都非常感谢。