Last active
May 22, 2019 07:41
-
-
Save maatthc/47c807ad65de57a6ad700eae8de69dce to your computer and use it in GitHub Desktop.
Find the latest file in a AWS S3 Bucket using Boto3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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