使用 Pandas AWS Glue Python Shell 作业

Using Pandas AWS Glue Python Shell Jobs

AWS 文档 https://docs.aws.amazon.com/glue/latest/dg/add-job-python.html

提到

The environment for running a Python shell job supports the following libraries:

...

pandas (required to be installed via the python setuptools configuration, setup.py)

但是没有提到如何安装。

如何在 AWS Glue Python Shell 作业中使用 Pandas?

  1. 转到 https://docs.aws.amazon.com/glue/latest/dg/add-job-python.html#create-python-extra-library。检查部分 为 'how to create setup file for python shell job'
  2. 创建 Python .egg 或 .whl 文件
  3. 在 setup.py 文件中,添加行 install_requires=['pandas==0.25.1']:
setup(name="<module name>",
        version="0.1",
        packages=['<package name if any or ignore>'],
        install_requires=['pandas==0.25.1']
    )

我还编写了小型 shell 脚本来部署 python shell 作业,无需手动步骤即可创建 egg 文件并上传到 s3 并通过 cloudformation 进行部署。脚本自动完成。 您可以在 https://github.com/fatangare/aws-python-shell-deploy

找到代码

只是为了澄清 Sandeep 的回答,以下是对我有用的方法

1/ 忽略 AWS 文档

2/ 创建一个 setup.py 文件包含:

from setuptools import setup

setup(name="pandasmodule",
        version="0.1",
        packages=[],
        install_requires=['pandas==0.25.1']
    )

3/ 运行 这个命令在包含文件的文件夹中:

python setup.py bdist_wheel

4/ 上传.whl文件到s3

5/ 将 Glue ETL 作业中的 "Python lib path" 配置为 s3 路径

您现在可以在 Glue ETL 作业中使用“import pandas as pd

无需执行任何操作,只需导入 pandas 即可开始使用。

AWS Glue 2.0 支持 pandas—1.0.1 https://docs.aws.amazon.com/glue/latest/dg/reduced-start-times-spark-etl-jobs.html

所以在你的脚本中你可以简单地写:import pandas。 如果你想使用 Glue 中没有提供的其他 python 模块,你可以下载 .whl 或 .zip -> 将它存储在 S3 -> 将它的路径放在 "Python library 中的 glue job 中path”和 glue during a job 运行 将执行 pip install “yourmodule”