Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aws Programmatic launch batch job

Hey I have the following function to launch a batch job.

My batch job has two parameters to be passed in --source --destination

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)

My job is being launched from batch, but my container is failing to launch due to how I am passing in --source and --dest. Here is the error log

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

How can I fix my command list to pass in the proper arguments. When I launch job at the command line I would just type --source file, --dest file


1 Answers

The answer to this for future reference

    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)

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!