title: Connect to mysql rds using python lambda
body: <p>I am very new to python code and doing some small tests to verify functionality</p>
  <p>Currently trying to establish the connection between an RDS MySQL and a python lambda function.</p>
  <p>However, it seems to fail in the code itself and I am not sure why this happens.
  There are a couple of guides out there but they all seem to be outdated and fail to work for me.</p>
  <p>These are the steps I took to get it working(using MAC-12.3.1 and VS-Studio 1.62.3):</p>
  <ol>
  <li>created MYSQL RDS</li>
  <li>connected to the MYSQL RDS and created a database called &quot;igor&quot; with table name &quot;lumigor&quot;, with 2 columns: id and name (populated with random data).</li>
  <li>created on the local machine a folder to contain the code and the package.</li>
  <li>installed version Python 3.8.9</li>
  <li>created lambda function file app.py with the following code:</li>
  </ol>
  <pre><code>import pymysql.cursors
  
  # Connect to the database
  connection = pymysql.connect(host='rds end point',
                              user='user',
                              password='pswrd',
                              database='igor',
                              cursorclass=pymysql.cursors.DictCursor)
  
  with connection:
     with connection.cursor() as cursor:
         # Read a single record
         sql = &quot;SELECT * FROM `Lumigor`&quot;
         cursor.execute(sql, ('webmaster@python.org',))
         result = cursor.fetchone()
         print(result)
     ```
  </code></pre>
  <ol>
  <li>I added requirement.txt file with the following command</li>
  </ol>
  <pre><code>python3 -m pip install PyMySQL &amp;&amp; pip3 freeze &gt; requirements.txt --target...
  </code></pre>
  <p>But now I get an error from the visual studio:</p>
  <p>&quot;Import &quot;pymysql.cursors&quot; could not be resolved from sourcePylance&quot;</p>
  <p>When I zip the file and upload it to lambda, run a test it returns an error</p>
  <pre><code>{
    &quot;errorMessage&quot;: &quot;Unable to import module 'app': No module named 'pymysql.cursors'&quot;,
    &quot;errorType&quot;: &quot;Runtime.ImportModuleError&quot;,
    &quot;stackTrace&quot;: []
  }
  </code></pre>
  <p>It seems like the dependcies are missing even though installed them and they exist in the directory</p>