从Glue脚本访问作业参数

0

【以下的问题经过翻译处理】 我定义了一个接受参数的Glue任务,但找不到如何访问这些参数的示例?

profile picture
ESPERTO
posta 6 mesi fa2 visualizzazioni
1 Risposta
0

【以下的回答经过翻译处理】 你可以像使用常规的Python sys.argv参数一样读取参数。

import sys
print "This is the name of the script: ", sys.argv[0]
print "Number of arguments: ", len(sys.argv)
print "The arguments are: " , str(sys.argv)

或者,你可以使用Glue的getResolvedOptions按名称读取参数。在这种情况下,你需要在参数名前加上“--”例如 --Arg1 Value1

from awsglue.utils import getResolvedOptions
args = getResolvedOptions(sys.argv, ['TempDir','JOB_NAME', 'Arg1'])
print "The args are:",str(args)
print "The value is:",args['Arg1']
profile picture
ESPERTO
con risposta 6 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande