简体   繁体   English

使用aws连接到mariadb lambda function

[英]connect to mariadb using aws lambda function

I have a layer where I have installed mariadb and requests .我有一个层,我已经安装了mariadbrequests The layer file is a zip archive of python\lib\python3.9\site-packages .图层文件是python\lib\python3.9\site-packages的 zip 存档。 Inside the site-packages , it looks like:site-packages内部,它看起来像:

├── bin
├── certifi
├── certifi-2022.6.15.2.dist-info
├── charset_normalizer
├── charset_normalizer-2.1.1.dist-info
├── google
├── idna
├── idna-3.3.dist-info
├── mariadb
├── mariadb-1.1.4.dist-info
├── protobuf-3.20.1.dist-info
├── protobuf-3.20.1-py3.10-nspkg.pth
├── requests
├── requests-2.28.1.dist-info
├── urllib3
└── urllib3-1.26.12.dist-info

The AWS lambda function for now only has following code: AWS lambda function 目前只有以下代码:

import requests
from mariadb import connect

When I test it, I get the following error当我测试它时,出现以下错误

{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'mariadb._mariadb'",
  "errorType": "Runtime.ImportModuleError",
  "requestId": "########",
  "stackTrace": []
}

How do I resolve this issue?我该如何解决这个问题?

I could not get mariadb library to work with lambda functions.我无法获得mariadb库来使用lambda函数。 I suspect installing just the python package alone is not enough as it also requires the MariaDB Connector/C .我怀疑仅安装 python package 是不够的,因为它还需要MariaDB Connector/C I eventually replaced mariadb with PyMySQL to make it work.我最终用mariadb替换了PyMySQL以使其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM