My s3 filename is 'folder/filename.xml'. i want to take the files end with 'name.xml'
import boto3
s3 = boto3.resource('s3')
try:
fileobj = s3.Object('lcu-matillion',''folder/.*name.xml'').get()['Body']
data=fileobj.read()
except Exception:
print('not found')
Any one please help with accurate code? Thanks
Don't forget that there could be multiple files that match that wildcard.
You would use something like:
import boto3
s3 = boto3.resource('s3', region_name='ap-southeast-2')
bucket = s3.Bucket('my-bucket')
objects = bucket.objects.filter(Prefix='folder-name/')
for object in objects:
if object.key.endswith('.txt'):
object.download_file('/tmp/' + object.key)
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