如何使用python shell在胶水作业中添加外部库

时间:2020-09-09 15:00:49

标签: aws-glue

我尝试通过在AWS配置https://docs.aws.amazon.com/glue/latest/dg/add-job-python.html中提到的作业配置中添加外部依赖项(例如pyathena,pytest等)作为python egg文件/ whl文件在python-shell中运行Glue作业。

Glue作业是在没有Internet的VPC下配置的,其执行导致以下错误。

警告:目录“ /.cache/pip”或其父目录不是 当前用户拥有或不可写。缓存已经 禁用的。检查该目录的权限和所有者。如果 用sudo执行pip,您可能需要sudo的-H标志。

警告:正在重试(重试(总计= 4,连接=无,读取=无, 断开连接后,重定向=无,状态=无)) 'ConnectTimeoutError(,“与pypi.org的连接超时。 (连接 timeout = 15)')'

我什至尝试使用以下代码修改python脚本

import os
import site
import importlib
from setuptools.command import easy_install
install_path = os.environ['GLUE_INSTALLATION']

libraries = ["pyathena"]

for lib in libraries:
    easy_install.main( ["--install-dir", install_path , lib] )

importlib.reload(site)

执行上述代码时,我遇到以下错误

https://pypi.org/simple/pyathena/上的下载错误:[Errno 99]无法 分配请求的地址-可能找不到某些软件包!不能 查找“ pyathena”的索引页(可能拼写错误?)

我可以提供示例代码片段来为外部python软件包生成一个egg / whl文件并添加Glue python-shell作业的那些部分

1 个答案:

答案 0 :(得分:1)

请参阅此doc,其中详细介绍了打包python库的步骤。另外,请确保您的VPC具有s3端点enter link description here,因为当您在VPC中运行Glue作业时流量不会离开AWS网络。