title: Problems using MySQL with AWS Lambda in Python
body: <p>I am trying to get up and running with AWS Lambda Python (beginner in Python btw) but having some problems with including MySQL dependency. I am trying to follow the instructions <a href="http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html">here</a> on my Mac.</p>
  
  <p>For step number 3, I am getting some problems with doing the command at the root of my project</p>
  
  <pre><code>sudo pip install MySQL-python -t /
  </code></pre>
  
  <p>Error: </p>
  
  <blockquote>
    <p>Exception:
    Traceback (most recent call last):
      File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
        status = self.run(options, args)
      File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 311, in run
        os.path.join(options.target_dir, item)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 292, in move
        raise Error, "Destination path '%s' already exists" % real_dst
    Error: Destination path '/MySQL_python-1.2.5-py2.7.egg-info/MySQL_python-1.2.5-py2.7.egg-info' already exists</p>
  </blockquote>
  
  <p>I end up writing my following lambda function (works fine on my Mac), which is: </p>
  
  <pre><code>import MySQLdb
  
  def lambda_handler(event, context):
     # Open database connection
     db = MySQLdb.connect(...)
  
     # prepare a cursor object using cursor() method
     cursor = db.cursor()
  
     sql = "SELECT * FROM Users"
  
     try:
        # Execute the SQL command
        cursor.execute(sql)
        # Fetch all the rows in a list of lists.
        results = cursor.fetchall()
        for row in results:
           fname = row[0]
           lname = row[1]
           age = row[2]
           sex = row[3]
           income = row[4]
           # Now print fetched result
           print ("lname=%s" %(lname))
     except:
        print "Error: unable to fecth data"
  
     # disconnect from server
     db.close()
  </code></pre>
  
  <p>What I went on to do is go to /Library/Python/2.7/site-packages and copying over the the MySQLdb folders/files that were downloaded when I did sudo pip install MySQL-python (without -t /) (I'm sure I'm doing something wrong here), to my lambda project, and then zipped the content along with the lambda_function.py and uploaded to AWS Lambda. </p>
  
  <p>Then I get:</p>
  
  <blockquote>
    <p>Unable to import module 'lambda_function': No module named MySQLdb</p>
  </blockquote>
  
  <p>Grateful for any help and suggestions!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Was able to do make sudo pip install MySQL-python -t /pathToProject work (thanks for the help in the comments) but now I get this when runing the lambda function:</p>
  
  <blockquote>
    <p>Unable to import module 'lambda_function': /var/task/_mysql.so: invalid ELF header</p>
  </blockquote>
  
  <p>I know that if I work on a Linux box, then it should work fine (as suggested by some people), but I am wondering if I can make it work from an OS X box.</p>