Cloud based object storage has become an important part of any software application stack in recent times. AWS S3 has become the de-facto choice for this use case.
import boto3
s3_resource = boto3.resource(
"s3",
aws_access_key_id="**********",
aws_secret_access_key="**********",
)
bucket
variable as name of the S3 bucketprefix
variable as name of S3 folder structure prefix. For eg. for file name like s3://bucketname/[clientid]/file1.csv
, clientid can be used as prefix to get only files starting with a particular clientid.list_objects_v2
method to get a list of matching file objects
obj = s3_resource.meta.client.list_objects_v2(Bucket=bucket, Prefix=prefix)
all_keys_obj = obj['Contents']
[
{'Key': '*****', 'LastModified': datetime.datetime(2020, 3, 3, 12, 16, 16, tzinfo=tzutc()), 'ETag': '"*****"', 'Size': 869061, 'StorageClass': 'STANDARD', 'Owner': {'ID': '*****'}},
....
{'Key': '*****', 'LastModified': datetime.datetime(2020, 3, 3, 12, 18, 10, tzinfo=tzutc()), 'ETag': '"*****"', 'Size': 23333915, 'StorageClass': 'STANDARD', 'Owner': {'ID': '*****'}}
]