def get_user_script(self): script = "" if utils.is_variable_in_environment('INIT_SCRIPT_PATH'): file_content = utils.read_file(utils.get_environment_variable('INIT_SCRIPT_PATH'), 'rb') script = utils.utf8_to_base64_string(file_content) if utils.is_value_in_dict(self.lambda_instance.event, 'script'): script = self.lambda_instance.event['script'] return script
def get_payload(self): # Default payload payload = {} if 'run_script' in self.properties: file_content = utils.read_file(self.properties['run_script'], 'rb') # We first code to base64 in bytes and then decode those bytes to allow the json lib to parse the data # https://stackoverflow.com/questions/37225035/serialize-in-json-a-base64-encoded-data#37239382 payload = {"script": utils.utf8_to_base64_string(file_content)} if 'c_args' in self.properties: payload = {"cmd_args": json.dumps(self.properties['c_args'])} return json.dumps(payload)
def set_properties(self, args): # Set the command line parsed properties self.properties = utils.merge_dicts(self.properties, vars(args)) call_type = self.set_call_type(args.func.__name__) self.set_output_type() if ((call_type != CallType.LS) and (not self.delete_all()) and (call_type != CallType.PUT) and (call_type != CallType.GET)): if (call_type == CallType.INIT): if (not self.get_property("name")) or ( self.get_property("name") == ""): func_name = "function" if self.get_property("image_id") != "": func_name = self.get_property("image_id") elif self.get_property("image_file") != "": func_name = self.get_property("image_file").split( '.')[0] self.properties["name"] = self.create_function_name( func_name) self.set_tags() self.check_function_name() function_name = self.get_property("name") validators.validate_function_name(function_name, self.get_property("name_regex")) self.set_environment_variables() self.properties["handler"] = function_name + ".lambda_handler" self.properties["log_group_name"] = '/aws/lambda/' + function_name if (call_type == CallType.INIT): self.set_function_code() if (call_type == CallType.RUN): if self.get_argument_value(args, 'run_script'): file_content = utils.read_file( self.get_property("run_script"), 'rb') # We first code to base64 in bytes and then decode those bytes to allow json to work # https://stackoverflow.com/questions/37225035/serialize-in-json-a-base64-encoded-data#37239382 parsed_script = utils.utf8_to_base64_string(file_content) self.set_property('payload', {"script": parsed_script}) if self.get_argument_value(args, 'c_args'): parsed_cont_args = json.dumps(self.get_property("c_args")) self.set_property('payload', {"cmd_args": parsed_cont_args})