我在AWS Lambda Service中使用Python SQLAlchemy时遇到问题

时间:2016-10-26 13:26:57

标签: python amazon-web-services aws-lambda

代码在虚拟环境中工作正常,我正在使用所有依赖项正确部署代码但是当我的代码尝试使用SQLAlchemy执行SQL原始查询时,我得到了这个

{
"stackTrace": [
[
  "/var/task/aws_handler.py",
  13,
  "twilio_handler",
  "sms_bot.handle_communication(message_body, recipient)"
],
[
  "/var/task/sms_bot.py",
  86,
  "handle_communication",
  "is_authenticated, user_id = self.authenticate_user(recipient)"
],
[
  "/var/task/sms_bot.py",
  38,
  "authenticate_user",
  "result = execute_query(query)"
],
[
  "/var/task/db_handler.py",
  28,
  "execute_query",
  "connection = get_db_connection()"
],
[
  "/var/task/db_handler.py",
  19,
  "get_db_connection",
  "return get_sqlalchemy_engine().connect()"
],
[
  "/var/task/db_handler.py",
  11,
  "get_sqlalchemy_engine",
  "return create_engine(SQLALCHEMY_DATABASE_URI)"
],
[
  "/var/task/sqlalchemy/engine/__init__.py",
  386,
  "create_engine",
  "return strategy.create(*args, **kwargs)"
],
[
  "/var/task/sqlalchemy/engine/strategies.py",
  75,
  "create",
  "dbapi = dialect_cls.dbapi(**dbapi_args)"
],
[
  "/var/task/sqlalchemy/dialects/mysql/mysqldb.py",
  92,
  "dbapi",
  "return __import__('MySQLdb')"
],
[
  "/var/task/MySQLdb/__init__.py",
  19,
  "<module>",
  "import _mysql"
]
  ],
   "errorType": "ImportError",
   "errorMessage":
   "libmysqlclient.so.20: cannot open shared object  file: No such 

    file or directory"}

注意:SQL_URI正确且在本地工作

1 个答案:

答案 0 :(得分:1)

我找到了解决方案,已安装

  

的libmysqlclient-dev的

在我的电脑上并复制

  

libmysqlclient.so.20

来自

  

/ usr / lib中/ x86_64的-Linux的GNU /

到我的aws部署包,将权限更改为777,压缩所有文件并上传到aws。它奏效了。