AWS Glue Python外壳程序包导入

AWS Glue Python外壳程序包导入,python,aws-glue,Python,Aws Glue,我们创建了一个Pythonshell作业,它连接红移和获取数据,下面的程序在我的本地系统中运行良好。 以下是步骤和程序 节目:- import sqlalchemy as sa from sqlalchemy.orm import sessionmaker #>>>>>>>> MAKE CHANGES HERE <<<<<<<<<<<<< DATABASE = "###

我们创建了一个Pythonshell作业,它连接红移和获取数据,下面的程序在我的本地系统中运行良好。 以下是步骤和程序

节目:-

import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker
#>>>>>>>> MAKE CHANGES HERE <<<<<<<<<<<<< 
DATABASE = "#####"
USER = "#####"
PASSWORD = "#####"
HOST = "#####.redshift.amazonaws.com"
PORT = "5439"
SCHEMA = "test"      #default is "public" 

####### connection and session creation ############## 
connection_string = "redshift+psycopg2://%s:%s@%s:%s/%s" % (USER,PASSWORD,HOST,str(PORT),DATABASE)
engine = sa.create_engine(connection_string)
session = sessionmaker()
session.configure(bind=engine)
s = session()
SetPath = "SET search_path TO %s" % SCHEMA
s.execute(SetPath)
###### All Set Session created using provided schema  #######
################ write queries from here ###################### 
query = "SELECT * FROM test1 limit 2;"
rr = s.execute(query)
all_results =  rr.fetchall()
def pretty(all_results):
    for row in all_results :
        print("row start >>>>>>>>>>>>>>>>>>>>")
        for r in row :
            print(" ----" , r)
        print("row end >>>>>>>>>>>>>>>>>>>>>>")
pretty(all_results)
########## close session in the end ###############
s.close()
将sqlalchemy作为sa导入
从sqlalchemy.orm导入sessionmaker

#>>>>>>>>在此进行更改您可以在“-extra py files”标志下指定打包为.egg或.whl文件的Python库,如下例所示

命令行示例:

aws glue create-job --name python-redshift-test-cli --role role --command '{"Name" :  "pythonshell", "ScriptLocation" : "s3://MyBucket/python/library/redshift_test.py"}' 
     --connections Connections=connection-name --default-arguments '{"--extra-py-files" : ["s3://MyBucket/python/library/redshift_module-0.1-py2.7.egg", "s3://MyBucket/python/library/redshift_module-0.1-py2.7-none-any.whl"]}'

referenece:

有一种使用whl文件导入python依赖项的简单方法,可以在python站点上找到特定模块的whl文件

您还可以使用逗号从S3添加多个控制盘文件

例如 “s3://xxxxxxxxx/common/glue/glue\u whl/fastparquet-0.4.1-cp37-cp37m-macosx\u 10\u 9\u x86\u 64.whl,s3://xxxxxx/common/glue/glue\u whl/packaging-20.4-py2.py3无任何。whl,s3://xxxxxx/common/glue/glue\u whl/s3fs-0.5.0-py3-none-any.whl”


您可以尝试将这些文件以--extra-py文件而不是库路径的形式传递吗?还可以传递每个文件的绝对路径(以逗号分隔)。您好,我已经完成了以lib文件分隔的(逗号(“,”)传递。现在是另一个问题。“警告:目录'/.cache/pip/http'或其父目录不属于当前用户,并且缓存已被禁用。请检查该目录的权限和所有者。如果使用sudo执行pip,您可能需要sudo的-H标志。”您好,我已完成此操作,现在收到此错误:-警告:重试(重试(total=0,connect=None,read=None,redirect=None,status=None))在连接被“ConnectTimeoutError(,“到pypi.org的连接超时。(connect timeout=15)”中断后:/simple/sqlalchemy/ERROR:找不到满足要求sqlalchemy>=0.8.0(来自Flask sqlalchemy==2.4.1)(来自版本:无)的版本错误:在下载和安装(args.extra_py_files)文件/tmp/runscript.py第63行下载和安装子流程中,未找到SQLAlchemy>=0.8.0(来自Flask SQLAlchemy==2.4.1)的回溯(最近一次调用):文件“/tmp/runscript.py”,第113行--target={}.format(install_path),local_file_path])file“/usr/local/lib/python2.7/subprocess.py”,在check_call raise CalledProcessError(retcode,cmd)subprocess中的第190行。CalledProcessError:Command'['/usr/local/bin/python','-m',pip',install','-target=/glue/lib/installation',@DeepeshUniyal能否添加aws cli命令的代码段。从上面的代码看,它似乎试图从Flask_sqlalchemy whl加载sqlalchemy,但找不到它。@DeepeshUniyal:我也看到了您正在使用的本地环境”pip安装sqlalchemy"在本例中,您正在通过flask_sqlalchemy。有什么具体原因吗?我在您的代码中没有看到任何flask依赖项。您好,下面给出的链接现在依赖项问题已经解决,但现在无法连接红移,似乎是安全问题,红移已经打开,我可以从任何地方手动访问它,但不能从gl访问它ue job.Logs:-文件“/tmp/glue-python-scripts-gm07eo/redshift_test.py”,第3行,文件“/glue/lib/installation/redshift_module-0.1-py2.7.egg/redshift_module/pygresql_redshift_common.py”,第8行:无法连接到服务器:连接超时主机“testap-south-1.redshift.amazonaws.com”(14.236.218.0)以及在端口5439上接受TCP/IP连接?
aws glue create-job --name python-redshift-test-cli --role role --command '{"Name" :  "pythonshell", "ScriptLocation" : "s3://MyBucket/python/library/redshift_test.py"}' 
     --connections Connections=connection-name --default-arguments '{"--extra-py-files" : ["s3://MyBucket/python/library/redshift_module-0.1-py2.7.egg", "s3://MyBucket/python/library/redshift_module-0.1-py2.7-none-any.whl"]}'