def invoke_function_batch(self,scar_input_file,variables): self.register_job_definition(lambda_instance.function_name, utils.get_environment_variable("IMAGE_ID")) data="" if utils.is_variable_in_environment('INIT_SCRIPT_PATH') : with open(str(os.environ['INIT_SCRIPT_PATH'])) as myfile: data = myfile.read() if utils.is_value_in_dict(lambda_instance.event, 'script'): data=utils.base64_to_utf8_string(lambda_instance.event['script']) if lambda_instance.has_input_bucket(): self.bucket_name_input = lambda_instance.input_bucket if lambda_instance.has_output_bucket(): self.bucket_name_output = lambda_instance.output_bucket if (data!=""): self.register_job_definition("scarfiles",self.scarfile_id_image) response = self.submit_job("scarfiles",1,"INIT",data,self.bucket_name_input,self.bucket_name_output,"script.sh",scar_input_file,variables) idJob = self.submit_job(lambda_instance.function_name,1,"MED",data,self.bucket_name_input,self.bucket_name_output,lambda_instance.input_folder+"/script.sh",scar_input_file,variables,idJob=response["jobId"])["jobId"] response = self.submit_job("scarfiles",1,"FINISH",data,self.bucket_name_input,self.bucket_name_output,"script.sh",scar_input_file,variables,idJob=idJob) elif(self.bucket_name_output!="NO" or self.bucket_name_input!="NO"): self.register_job_definition("scarfiles",self.scarfile_id_image) response = self.submit_job("scarfiles",1,"INIT",data,self.bucket_name_input,self.bucket_name_output,"",scar_input_file,variables) idJob = self.submit_job(lambda_instance.function_name,1,"MED",data,self.bucket_name_input,self.bucket_name_output,"",scar_input_file,variables,idJob=response["jobId"])["jobId"] response = self.submit_job("scarfiles",1,"FINISH",data,self.bucket_name_input,self.bucket_name_output,"",scar_input_file,variables,idJob=idJob) else: idJob = self.submit_job(lambda_instance.function_name,1,"MED",data,self.bucket_name_input,self.bucket_name_output,"",scar_input_file,variables)["jobId"] return idJob
def add_script_as_entrypoint(self): script_path = "{0}/script.sh".format(lambda_instance.temporal_folder) script_content = utils.base64_to_utf8_string( lambda_instance.event['script']) utils.create_file_with_content(script_path, script_content) self.cmd_container_execution += [ "--entrypoint={0} {1}".format(self.script_exec, script_path), self.container_name ]
def create_command(self): self.add_container_volumes() self.add_container_environment_variables() # Container running script if utils.is_value_in_dict(self.lambda_instance.event, 'script'): # Add script in memory as entrypoint script_path = "{0}/script.sh".format(self.lambda_instance.temporal_folder) script_content = utils.base64_to_utf8_string(self.lambda_instance.event['script']) utils.create_file_with_content(script_path, script_content) self.cmd_container_execution += ["--entrypoint={0} {1}".format(self.script_exec, script_path), self.container_name] # Container with args elif utils.is_value_in_dict(self.lambda_instance.event,'cmd_args'): # Add args self.cmd_container_execution += [self.container_name] self.cmd_container_execution += json.loads(self.lambda_instance.event['cmd_args']) # Script to be executed every time (if defined) elif utils.is_variable_in_environment('INIT_SCRIPT_PATH'): # Add init script init_script_path = "{0}/init_script.sh".format(self.lambda_instance.temporal_folder) shutil.copyfile(utils.get_environment_variable("INIT_SCRIPT_PATH"), init_script_path) self.cmd_container_execution += ["--entrypoint={0} {1}".format(self.script_exec, init_script_path), self.container_name] # Only container else: self.cmd_container_execution += [self.container_name]
def parse_base64_response_values(value): value['LogResult'] = utils.base64_to_utf8_string(value['LogResult']) value['ResponseMetadata']['HTTPHeaders'][ 'x-amz-log-result'] = utils.base64_to_utf8_string( value['ResponseMetadata']['HTTPHeaders']['x-amz-log-result'])
def _copy_user_script(self): utils.create_file_with_content( utils.join_paths(self.function_image_folder, 'user_script.sh'), utils.base64_to_utf8_string(self.function_args['script']))