@@ -109,7 +109,7 @@ def deploy(
109109 local_package = local_package ,
110110 )
111111
112- if function_exists (cfg , cfg . get ( 'function_name' ) ):
112+ if function_exists (cfg ):
113113 update_function (cfg , path_to_zip_file )
114114 else :
115115 create_function (cfg , path_to_zip_file )
@@ -143,7 +143,7 @@ def deploy_s3(
143143
144144 use_s3 = True
145145 s3_file = upload_s3 (cfg , path_to_zip_file , use_s3 )
146- if function_exists (cfg , cfg . get ( 'function_name' ) ):
146+ if function_exists (cfg ):
147147 update_function (cfg , path_to_zip_file , use_s3 = use_s3 , s3_file = s3_file )
148148 else :
149149 create_function (cfg , path_to_zip_file , use_s3 = use_s3 , s3_file = s3_file )
@@ -663,9 +663,10 @@ def upload_s3(cfg, path_to_zip_file, *use_s3):
663663 return filename
664664
665665
666- def function_exists (cfg , function_name ):
666+ def function_exists (cfg ):
667667 """Check whether a function exists or not"""
668668
669+ function_name = cfg .get ('function_name' )
669670 profile_name = cfg .get ('profile' )
670671 aws_access_key_id = cfg .get ('aws_access_key_id' )
671672 aws_secret_access_key = cfg .get ('aws_secret_access_key' )
@@ -674,22 +675,11 @@ def function_exists(cfg, function_name):
674675 cfg .get ('region' ),
675676 )
676677
677- # Need to loop through until we get all of the lambda functions returned.
678- # It appears to be only returning 50 functions at a time.
679- functions = []
680- functions_resp = client .list_functions ()
681- functions .extend ([
682- f ['FunctionName' ] for f in functions_resp .get ('Functions' , [])
683- ])
684- while ('NextMarker' in functions_resp ):
685- functions_resp = client .list_functions (
686- Marker = functions_resp .get ('NextMarker' ),
687- )
688- functions .extend ([
689- f ['FunctionName' ] for f in functions_resp .get ('Functions' , [])
690- ])
691- return function_name in functions
692-
678+ try :
679+ return client .get_function (FunctionName = function_name )
680+ except client .exceptions .ResourceNotFoundException as e :
681+ if 'Function not found' in str (e ):
682+ return False
693683
694684def read_cfg (path_to_config_file , profile_name ):
695685 cfg = read (path_to_config_file , loader = yaml .load )
0 commit comments