【问题标题】:Aws Programmatic launch batch jobAws Programmatic 启动批处理作业
【发布时间】:2019-01-09 09:07:28
【问题描述】:

嘿,我有以下功能来启动批处理作业。

我的批处理作业有两个参数要传入 - 资源 --目的地

def kickoff_transfer_batch(self,item):
    try:
        batch = boto3.client('batch')
        bucket, key = get_s3_bucket_and_key(item.source)
        jobName = 'transfer-'+ key
        jobQueue = 'aws-strikeforce-on-demand-restore-prod'
        jobDefinition = 'aws-strikeforce-transfer-prod'
        source = '--source ' + item.source
        destination ='--destination ' + item.destination

        command = []
        command.append(source)
        command.append(destination)

        submit_job_response = batch.submit_job(
            jobName=jobName,
            jobQueue=jobQueue,
            jobDefinition=jobDefinition,
            containerOverrides={'command': command}
        )
        job_id = submit_job_response['jobId']
        print('Submitted job {} {} to the job queue {}'.format(jobName, job_id, jobQueue))
    except Exception as err:
        item.errored = True
        print("failed: " + item.source)
        print("error: " + str(err))
        stack_trace = traceback.format_exc()
        self._log_error_notes(item.source, err, stack_trace)

我的作业正在从批处理中启动,但由于我传递 --source 和 --dest 的方式,我的容器无法启动。 这是错误日志

main.py: error: unrecognized arguments: --source file_test.txt --destination file_test.txt

如何修复我的命令列表以传递正确的参数。 当我在命令行启动作业时,我只需键入 --source 文件,--dest 文件

【问题讨论】:

    标签: python-3.x amazon-web-services boto3 aws-batch


    【解决方案1】:

    这个问题的答案以供将来参考

        def kickoff_transfer_batch(self,item):
        try:
            batch = boto3.client('batch')
            bucket, key = get_s3_bucket_and_key(item.source)
            jobName = 'transfer-'+ key
            jobQueue = 'aws-strikeforce-on-demand-restore-prod'
            jobDefinition = 'aws-strikeforce-transfer-prod'
            command = '--source '+ item.source + '--destination ' + item.destination
            command = command.split()
    
            submit_job_response = batch.submit_job(
                jobName=jobName,
                jobQueue=jobQueue,
                jobDefinition=jobDefinition,
                containerOverrides={'command': command}
            )
            job_id = submit_job_response['jobId']
            print('Submitted job {} {} to the job queue {}'.format(jobName, job_id, jobQueue))
        except Exception as err:
            item.errored = True
            print("failed: " + item.source)
            print("error: " + str(err))
            stack_trace = traceback.format_exc()
            self._log_error_notes(item.source, err, stack_trace)
    

    【讨论】:

    • 类型的item变量是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 2014-12-12
    相关资源
    最近更新 更多