3333log = logging .getLogger (__name__ )
3434
3535
36- def cleanup_old_versions (src , keep_last_versions ):
36+ def cleanup_old_versions (src , keep_last_versions , config_file = 'config.yaml' ):
3737 """Deletes old deployed versions of the function in AWS Lambda.
3838
3939 Won't delete $Latest and any aliased version
@@ -47,7 +47,7 @@ def cleanup_old_versions(src, keep_last_versions):
4747 if keep_last_versions <= 0 :
4848 print ("Won't delete all versions. Please do this manually" )
4949 else :
50- path_to_config_file = os .path .join (src , 'config.yaml' )
50+ path_to_config_file = os .path .join (src , config_file )
5151 cfg = read (path_to_config_file , loader = yaml .load )
5252
5353 aws_access_key_id = cfg .get ('aws_access_key_id' )
@@ -78,7 +78,7 @@ def cleanup_old_versions(src, keep_last_versions):
7878 .format (version_number , e .message ))
7979
8080
81- def deploy (src , requirements = False , local_package = None ):
81+ def deploy (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
8282 """Deploys a new function to AWS Lambda.
8383
8484 :param str src:
@@ -89,22 +89,23 @@ def deploy(src, requirements=False, local_package=None):
8989 well (and/or is not available on PyPi)
9090 """
9191 # Load and parse the config file.
92- path_to_config_file = os .path .join (src , 'config.yaml' )
92+ path_to_config_file = os .path .join (src , config_file )
9393 cfg = read (path_to_config_file , loader = yaml .load )
9494
9595 # Copy all the pip dependencies required to run your code into a temporary
9696 # folder then add the handler file in the root of this directory.
9797 # Zip the contents of this folder into a single file and output to the dist
9898 # directory.
99- path_to_zip_file = build (src , requirements , local_package )
99+ path_to_zip_file = build (
100+ src , config_file = config_file , requirements = requirements , local_package = local_package )
100101
101102 if function_exists (cfg , cfg .get ('function_name' )):
102103 update_function (cfg , path_to_zip_file )
103104 else :
104105 create_function (cfg , path_to_zip_file )
105106
106107
107- def deploy_s3 (src , requirements = False , local_package = None ):
108+ def deploy_s3 (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
108109 """Deploys a new function via AWS S3.
109110
110111 :param str src:
@@ -115,14 +116,15 @@ def deploy_s3(src, requirements=False, local_package=None):
115116 well (and/or is not available on PyPi)
116117 """
117118 # Load and parse the config file.
118- path_to_config_file = os .path .join (src , 'config.yaml' )
119+ path_to_config_file = os .path .join (src , config_file )
119120 cfg = read (path_to_config_file , loader = yaml .load )
120121
121122 # Copy all the pip dependencies required to run your code into a temporary
122123 # folder then add the handler file in the root of this directory.
123124 # Zip the contents of this folder into a single file and output to the dist
124125 # directory.
125- path_to_zip_file = build (src , requirements , local_package )
126+ path_to_zip_file = build (
127+ src , config_file = config_file , requirements = requirements , local_package = local_package )
126128
127129 use_s3 = True
128130 s3_file = upload_s3 (cfg , path_to_zip_file , use_s3 )
@@ -132,7 +134,7 @@ def deploy_s3(src, requirements=False, local_package=None):
132134 create_function (cfg , path_to_zip_file , use_s3 , s3_file )
133135
134136
135- def upload (src , requirements = False , local_package = None ):
137+ def upload (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
136138 """Uploads a new function to AWS S3.
137139
138140 :param str src:
@@ -143,19 +145,20 @@ def upload(src, requirements=False, local_package=None):
143145 well (and/or is not available on PyPi)
144146 """
145147 # Load and parse the config file.
146- path_to_config_file = os .path .join (src , 'config.yaml' )
148+ path_to_config_file = os .path .join (src , config_file )
147149 cfg = read (path_to_config_file , loader = yaml .load )
148150
149151 # Copy all the pip dependencies required to run your code into a temporary
150152 # folder then add the handler file in the root of this directory.
151153 # Zip the contents of this folder into a single file and output to the dist
152154 # directory.
153- path_to_zip_file = build (src , requirements , local_package )
155+ path_to_zip_file = build (
156+ src , config_file = config_file , requirements = requirements , local_package = local_package )
154157
155158 upload_s3 (cfg , path_to_zip_file )
156159
157160
158- def invoke (src , alt_event = None , verbose = False ):
161+ def invoke (src , event_file = 'event.json' , config_file = 'config.yaml' , verbose = False ):
159162 """Simulates a call to your function.
160163
161164 :param str src:
@@ -167,7 +170,7 @@ def invoke(src, alt_event=None, verbose=False):
167170 Whether to print out verbose details.
168171 """
169172 # Load and parse the config file.
170- path_to_config_file = os .path .join (src , 'config.yaml' )
173+ path_to_config_file = os .path .join (src , config_file )
171174 cfg = read (path_to_config_file , loader = yaml .load )
172175
173176 # Load environment variables from the config file into the actual
@@ -178,10 +181,7 @@ def invoke(src, alt_event=None, verbose=False):
178181 os .environ [key ] = value
179182
180183 # Load and parse event file.
181- if alt_event :
182- path_to_event_file = os .path .join (src , alt_event )
183- else :
184- path_to_event_file = os .path .join (src , 'event.json' )
184+ path_to_event_file = os .path .join (src , event_file )
185185 event = read (path_to_event_file , loader = json .loads )
186186
187187 # Tweak to allow module to import local modules
@@ -229,7 +229,7 @@ def init(src, minimal=False):
229229 copy (dest_path , src )
230230
231231
232- def build (src , requirements = False , local_package = None ):
232+ def build (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
233233 """Builds the file bundle.
234234
235235 :param str src:
@@ -240,7 +240,7 @@ def build(src, requirements=False, local_package=None):
240240 well (and/or is not available on PyPi)
241241 """
242242 # Load and parse the config file.
243- path_to_config_file = os .path .join (src , 'config.yaml' )
243+ path_to_config_file = os .path .join (src , config_file )
244244 cfg = read (path_to_config_file , loader = yaml .load )
245245
246246 # Get the absolute path to the output directory and create it if it doesn't
@@ -296,7 +296,7 @@ def build(src, requirements=False, local_package=None):
296296 if os .path .isfile (filename ):
297297 if filename == '.DS_Store' :
298298 continue
299- if filename == 'config.yaml' :
299+ if filename == config_file :
300300 continue
301301 print ('Bundling: %r' % filename )
302302 files .append (os .path .join (src , filename ))
0 commit comments