Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server与AWS GLUE Python 3作业的连接_Python_Sql Server_Python 3.x_Aws Glue_Python Glue - Fatal编程技术网

SQL Server与AWS GLUE Python 3作业的连接

SQL Server与AWS GLUE Python 3作业的连接,python,sql-server,python-3.x,aws-glue,python-glue,Python,Sql Server,Python 3.x,Aws Glue,Python Glue,我编写了一个python作业,该作业使用sqlAlchemy查询SQL Server数据库,但是,当使用带有AWS Glue的外部库时,需要将这些库包装到一个egg文件中。这导致sqlAlchemy包出现问题,因为它使用的pyodbc包不能封装在鸡蛋中,据我所知,它还有其他依赖项 我曾尝试在Python Glue作业中找到一种连接SQL Server数据库的方法,但到目前为止,我能找到的最接近的建议是,我改为编写一个Spark作业,这是不合适的 有没有人有在Python 3粘合作业中连接SQL

我编写了一个python作业,该作业使用sqlAlchemy查询SQL Server数据库,但是,当使用带有AWS Glue的外部库时,需要将这些库包装到一个egg文件中。这导致sqlAlchemy包出现问题,因为它使用的pyodbc包不能封装在鸡蛋中,据我所知,它还有其他依赖项

我曾尝试在Python Glue作业中找到一种连接SQL Server数据库的方法,但到目前为止,我能找到的最接近的建议是,我改为编写一个Spark作业,这是不合适的


有没有人有在Python 3粘合作业中连接SQL Server的经验?如果是这样的话,我可以使用一个代码+包的示例片段吗?

是的,我实际上通过捆绑依赖项(包括可传递依赖项)完成了类似的工作

请按照以下步骤操作:

1-创建一个脚本,将所有代码和依赖项压缩到zip文件中,并上载到S3:

python3 -m pip install -r requirements.txt --target custom_directory
python3 -m zipapp custom_directory/
mv custom_directory.pyz custom_directory.zip
上传这个拉链,而不是鸡蛋或轮子

2-创建一个驱动程序来执行我们在步骤1中压缩的python源程序

import sys

if len(sys.argv) == 1:
    raise SyntaxError("Please provide a module to load.")
sys.path.append(sys.argv[1])

from your_module import your_function
sys.exit(your_function())
3-然后,您可以使用以下方式提交作业:

spark-submit --py-files custom_directory.zip your_program.py
见: