title: How to get latest file-name or file from S3 bucket using event triggered lambda
body: <p>I am very new to AWS services and has just a week worth of experience with serverless architecture, My requirement is to trigger an event when a new file is uploaded to a specific bucket, once the event trigger is set my Lambda should get the details of the latest file such as Name, Size, and Date of creation.</p>
  
  <p>The source is uploading this file in a new folder every time and names the folder with the current date.</p>
  
  <p>So far I am able to crack how to create my Lambda function and listen to the event trigger.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>import boto3
  import botocore
  import datetime
  import logging
  
  def lambda_handler(event, context):
      logging.info('Start function')
      s3 = boto3.resource('s3')
      DATE = datetime.datetime.today().strftime('%Y-%m-%d')
      BUCKET_NAME = 'monkey-banana-dev'
      KEY = '/banana/incoming/daily/{}'.format(DATE)
      logging.info('Getting file from {}'.format(KEY))
      try:
          s3.Bucket(BUCKET_NAME).download_file(KEY, 'name_of_my_file')
      except botocore.exceptions.ClientError as e:
          if e.response['Error']['Code'] == "404":
              print("The object does not exist.")
          else:
              raise
  </code></pre>
  
  <p>here since I know that it's going to be today's date hence I am using <code>datetime</code> to get the exact KEY but file-name will always be different. although I know that it's going to be a text file with .txt suffix, I am not able to get around on how to get the name of the latest uploaded file and other details from the trigger.</p>