title: Update Text File Using Lambda
body: <p>I want to be able to update a text file whenever I upload an image to the s3 bucket. This text file will contain on each line the results of Amazon Rekognition. However, the code I've written isn't working properly</p>
  
  <pre><code>bucket_name = "update-my-text-file"
  rekognition = boto3.client('rekognition')
  s3 = boto3.resource('s3')
  bucket = s3.Bucket(bucket_name)
  
  def handle_image(key):
      response = rekognition.detect_labels(
          Image={
              'S3Object': {
                  'Bucket': bucket_name,
                  'Name': key
              }
          }
      )
      return response
  
  
  def lambda_handler(event, context):
  
      file_name = 'results.txt'
      object = s3.Object(bucket_name, 'tmp/results.txt')
  
      cli = boto3.client('s3')
      response = cli.get_object(Bucket=bucket_name, Key='tmp/results.txt')
      data = response['Body'].read()
      print('the data is ' + data)
  
      key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'].encode('utf8'))
      response = handle_image(key)
      print('the response is: ' + response)
  
      object.put(Body=data + '/n' + response)
  </code></pre>