diff --git a/zappa/cli.py b/zappa/cli.py index a89f9816a..e9b35bb38 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -2141,7 +2141,10 @@ def callback(self, position): working_dir = os.getcwd() working_dir_importer = pkgutil.get_importer(working_dir) - module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) + if self.runtime == "python3.12": + module_ = working_dir_importer.find_spec(mod_name).loader.load_module(mod_name) + else: + module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) except (ImportError, AttributeError): try: # Callback func might be in virtualenv @@ -2844,7 +2847,10 @@ def execute_prebuild_script(self): working_dir = os.getcwd() working_dir_importer = pkgutil.get_importer(working_dir) - module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) + if self.runtime == "python3.12": + module_ = working_dir_importer.find_spec(mod_name).loader.load_module(mod_name) + else: + module_ = working_dir_importer.find_module(mod_name).load_module(mod_name) except (ImportError, AttributeError): try: # Prebuild func might be in virtualenv