因此,我尝试在AWS Lambda的一个层中设置该软件包,以供以后在函数中使用。不幸的是,我似乎无法使env变量正常工作或对其进行正确设置,因此它可以读取google_secret.json
准备lambda包I:
build/python/lib/python3.7/site-packages
该过程适用于除此以外的所有其他软件包,因为我没有指向google_secret.json的配置
作为修复,我试图:
_default_dir = ( Path(environ.get("$XDG_CONFIG_HOME", Path(environ.get("HOME")) / ".config")) / "gspread_pandas"
)到我在python目录(已压缩)中创建的路径的位置,该路径用于存储google_secret.json:"python/config/gspread_pandas/"
"GSPREAD_PANDAS_CONFIG_DIR"
并将其设置为文件的路径不幸的是,上述方法均无效。
在两种情况下,我都会收到以下错误
{ "errorMessage": "expected str, bytes or os.PathLike object, not NoneType",
"errorType": "TypeError",
"stackTrace": [ " File \"/var/lang/lib/python3.7/imp.py\", line 234, in load_module\n return load_source(name, filename, file)\n",
" File \"/var/lang/lib/python3.7/imp.py\", line 171, in load_source\n module = _load(spec)\n",
" File \"<frozen importlib._bootstrap>\", line 696, in _load\n", " File \"<frozen importlib._bootstrap>\", line 677, in _load_unlocked\n",
" File \"<frozen importlib._bootstrap_external>\", line 728, in exec_module\n",
" File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n",
" File \"/var/task/lambda_function.py\", line 8, in <module>\n import gspread_pandas\n",
" File \"/opt/python/lib/python3.7/site-packages/gspread_pandas/__init__.py\", line 5, in <module>\n from .client import Client\n",
" File \"/opt/python/lib/python3.7/site-packages/gspread_pandas/client.py\", line 15, in <module>\n from gspread_pandas.conf import default_scope, get_creds\n",
" File \"/opt/python/lib/python3.7/site-packages/gspread_pandas/conf.py\", line 25, in <module>\n Path(environ.get(\"$XDG_CONFIG_HOME\", Path(environ.get(\"HOME\")) / \".config\"))\n",
" File \"/var/lang/lib/python3.7/pathlib.py\", line 1022, in __new__\n self = cls._from_parts(args, init=False)\n",
" File \"/var/lang/lib/python3.7/pathlib.py\", line 669, in _from_parts\n drv, root, parts = self._parse_args(args)\n",
" File \"/var/lang/lib/python3.7/pathlib.py\", line 653, in _parse_args\n a = os.fspath(a)\n" ] }
我不得不提一下,我没有太多的编码经验,因此我为不好的解释在此先表示歉意。
任何帮助将不胜感激!
这些步骤对我来说很好。
为您的图层创建此文件夹结构:
$ mkdir -p lambda_layers / python / lib / python3.7 / site-packages
将软件包放入site-packages文件夹:
$ pip install gspread-pandas -t lambda_layers / python / lib / python3.7 / site-packages /。
创建图层的zip文件:
$ cd lambda_layers
$ zip -r gspread-pandas_lambda_layer.zip *