所以我尝试在 AWS Lambda 的一个层中设置包,以便稍后在函数中使用它。不幸的是,我似乎无法使 env 变量工作或正确设置它,以便它可以读取 google_secret.json
准备 lambda 包我:
- 创建了一个 EC2 实例
- 创建本地目录:
build/python/lib/python3.7/site-packages
- 安装了我在该目录中使用的所有软件包,包括 gspread_pandas
- 压缩python目录
- 将其上传到 S3,然后将其用作图层
该过程适用于除此之外的所有其他包,因为我没有指向 google_secret.json 的配置
作为修复,我尝试:
- 将此配置文件中的路径更改
为我在存储 google_secret.json
_default_dir = ( Path(environ.get("$XDG_CONFIG_HOME", Path(environ.get("HOME")) / ".config")) / "gspread_pandas"
的 python 目录(已压缩)中创建的路径:"python/config/gspread_pandas/"
- 在 lambda 函数中创建文件 google_secret.json,创建环境变量
"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" ] }
我不得不提一下,我没有太多的编码经验,所以我提前为糟糕的解释道歉。
任何帮助将不胜感激!