python操作S3(aws)

it2022-05-05  150

import boto3 boto3_session = boto3.Session(aws_access_key_id=xxx, aws_secret_access_key=xxx, region_name='cn-north-1') # print(boto3_session.get_available_services()) # sys.exit(0) s3 = boto3_session.resource('s3') boto3_client = boto3_session.client('s3') # 使用boto3获取bucket列表 for bucket in s3.buckets.all(): print('bucket name:%s' % bucket.name) bucket = s3.Bucket('xx') # 查看桶中的内容 for obj in bucket.objects.all(): print('bucket obj key:%s' % obj.key) # 复制桶中的文件到另一个桶 copy_source = { 'Bucket': 'xx', 'Key': 'old/1000.gz' } s3.meta.client.copy(copy_source, 'xx', 'new/1000.gz')

最新回复(0)