【问题标题】:I am having an issue while using Python SQLAlchemy in AWS Lambda Service我在 AWS Lambda 服务中使用 Python SQLAlchemy 时遇到问题
【发布时间】:2016-10-26 13:26:56
【问题描述】:

代码在虚拟环境中运行良好,我正在使用所有依赖项正确部署代码,但是当我的代码尝试使用 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 正确且在本地工作

【问题讨论】:

  • 尝试卸载并重新安装 mysql python:pip uninstall mysql-python pip install mysql-python 检查此链接:stackoverflow.com/questions/34348752/…
  • 你的部署包里有libmysqlclient.so.20吗?
  • 不,它不在我的部署包中。我怎样才能包含它?

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


【解决方案1】:

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

libmysqlclient-dev

在我的电脑上复制

libmysqlclient.so.20

来自

/usr/lib/x86_64-linux-gnu/

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

【讨论】:

    猜你喜欢
    • 2022-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 2018-03-03
    相关资源
    最近更新 更多