Aws程序化启动批处理作业

时间:2018-08-01 17:42:33

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

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

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

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

如何修复命令列表以传递适当的参数。 当我在命令行启动作业时,我只需输入 -源文件,-目标文件

1 个答案:

答案 0 :(得分:0)

对此的答案以供将来参考

    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)
相关问题