title: Accessing Meta Data from AWS S3 with AWS Lambda
body: <p>I would like to retrieve some meta data I added (using the console x-amz-meta-my_variable) every time I upload an object to S3. </p>
  
  <p>I have set up lambda through the console to trigger every time an object is uploaded to my bucket</p>
  
  <p>I am wondering if I can use something like <code>variable = event['Records'][0]['s3']['object']['my_variable']</code> to retrieve this data or if I have to connect back to S3 with the bucket and key and then call some function to retrieve it?</p>
  
  <p>Below is the code: </p>
  
  <pre><code>from __future__ import print_function
  
  import json
  import urllib
  import boto3
  
  print('Loading function')
  
  s3 = boto3.client('s3')
  
  
  def lambda_handler(event, context):
  
      # Get the object from the event and show its content type
      bucket = event['Records'][0]['s3']['bucket']['name']
      key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8')
  
      # variable = event['Records'][0]['s3']['object']['my_variable']
  
      try:
          response = s3.get_object(Bucket=bucket, Key=key)
  
          # Call some function here?
  
          print("CONTENT TYPE: " + response['ContentType'])
          return response['ContentType']
  
      except Exception as e:
          print(e)
          print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
          raise e
  </code></pre>