Skip to content

Instantly share code, notes, and snippets.

@maatthc
Last active May 22, 2019 07:41
Show Gist options
  • Save maatthc/47c807ad65de57a6ad700eae8de69dce to your computer and use it in GitHub Desktop.
Save maatthc/47c807ad65de57a6ad700eae8de69dce to your computer and use it in GitHub Desktop.
Find the latest file in a AWS S3 Bucket using Boto3
import boto3
def find_latest_file_in_folder(bucket, path):
s3 = boto3.client('s3')
s3_keys = s3.list_objects_v2(Bucket=bucket, Prefix=path)['Contents']
last_added = max(s3_keys, key=lambda x: x['LastModified'])
return "%s/%s" % (bucket,last_added['Key'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment