0

I try to deploy an AWS lambda application, I implemented with the Chalice Python Framework. My app.py connects to a MySQL server and therefore has to

import mysql.connector

But on every invocation of one of my lambda functions I get an error in the log

'Unable to import module 'app': No module named mysql.connector'

I tried to add the mysql.connector to the requirements.txt file in the chalice project:

mysql_connector==2.1.6

And if I do so, 2 additional folders containing several files appear in the AWS lambda environment:

/mysql_connector-2.1.6.data

/mysql_connector-2.1.6.dist-info

But the error remains the same. How to deploy python mysql.connector with Chalice?

S.Schedel
  • 31
  • 3

1 Answers1

0

This finally worked for me:

lib_path=os.path.abspath(os.path.join(__file__, '..', 'mysql_connector-2.1.6.data', 'purelib'))
sys.path.append(lib_path)
import mysql.connector

Putting the "mysql_connector==2.1.6" into the "requirements.txt" file did install the mysql connector in lambda environment. I added the path of the package (../mysql_connector-2.1.6.data/purelib) to system path.

S.Schedel
  • 31
  • 3