I want to download the lastest file in a folder from a bucket in AmazonWeb services.Right now, i can dowload a file given a specific name.The problem is, in the folder there are several files with diferent names (usually combined with a date, ex :Prueba_010424.txt)so, how can I automatically detect the last one or the most recent one, without given its name and download it?
Thanks
# Librariesimport boto3# Create variables for S3 configurationAWS_ACCESS_KEY = "Mykey"AWS_SECRET_KEY = "MySecretKey"AWS_S3_BUCKET_NAME = "MyBucket"AWS_REGION = "MyRegion"# Create variables for file fileLOCAL_FILE = 'prueba.txt'OBJECT_FOR_S3 = ' Test/'+ LOCAL_FILE #To select the file Prueba in folder Test# Main processdef main(): print ('in main method') # Flag to know where the process is s3_client = boto3.client( service_name = 's3' , region_name = AWS_REGION , aws_access_key_id = AWS_ACCESS_KEY , aws_secret_access_key = AWS_SECRET_KEY ) response = s3_client.download_file(AWS_S3_BUCKET_NAME, OBJECT_FOR_S3, r'C:\test\prueba.txt') print(f'upload file responde: {response}' )if __name__ == '__main__' : main()