0

I have this below code that helps me find the latest file in a S3 bucket

from boto3.session import Session


session = Session(aws_access_key_id=AWS_ACCESS_KEY_ID,
                      aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
s3 = session.resource("s3")

get_last_modified = lambda obj: int(obj.last_modified.strftime('%s'))
bckt = s3.Bucket("bucket_name")
objs = [obj for obj in bckt.objects.all()]

objs = [obj for obj in sorted(objs, key=get_last_modified)]
last_added = objs[-1].key

I however would like to modify this such that I am checking for the latest file in a sub-folder and not the entire bucket

John Rotenstein
  • 203,710
  • 21
  • 304
  • 382
Kevin Nash
  • 1,215
  • 2
  • 15
  • 28

0 Answers0