33
33
log = logging .getLogger (__name__ )
34
34
35
35
36
- def cleanup_old_versions (src , keep_last_versions ):
36
+ def cleanup_old_versions (src , keep_last_versions , config_file = 'config.yaml' ):
37
37
"""Deletes old deployed versions of the function in AWS Lambda.
38
38
39
39
Won't delete $Latest and any aliased version
@@ -47,7 +47,7 @@ def cleanup_old_versions(src, keep_last_versions):
47
47
if keep_last_versions <= 0 :
48
48
print ("Won't delete all versions. Please do this manually" )
49
49
else :
50
- path_to_config_file = os .path .join (src , 'config.yaml' )
50
+ path_to_config_file = os .path .join (src , config_file )
51
51
cfg = read (path_to_config_file , loader = yaml .load )
52
52
53
53
aws_access_key_id = cfg .get ('aws_access_key_id' )
@@ -78,7 +78,7 @@ def cleanup_old_versions(src, keep_last_versions):
78
78
.format (version_number , e .message ))
79
79
80
80
81
- def deploy (src , requirements = False , local_package = None ):
81
+ def deploy (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
82
82
"""Deploys a new function to AWS Lambda.
83
83
84
84
:param str src:
@@ -89,22 +89,23 @@ def deploy(src, requirements=False, local_package=None):
89
89
well (and/or is not available on PyPi)
90
90
"""
91
91
# 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 )
93
93
cfg = read (path_to_config_file , loader = yaml .load )
94
94
95
95
# Copy all the pip dependencies required to run your code into a temporary
96
96
# folder then add the handler file in the root of this directory.
97
97
# Zip the contents of this folder into a single file and output to the dist
98
98
# 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 )
100
101
101
102
if function_exists (cfg , cfg .get ('function_name' )):
102
103
update_function (cfg , path_to_zip_file )
103
104
else :
104
105
create_function (cfg , path_to_zip_file )
105
106
106
107
107
- def deploy_s3 (src , requirements = False , local_package = None ):
108
+ def deploy_s3 (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
108
109
"""Deploys a new function via AWS S3.
109
110
110
111
:param str src:
@@ -115,14 +116,15 @@ def deploy_s3(src, requirements=False, local_package=None):
115
116
well (and/or is not available on PyPi)
116
117
"""
117
118
# 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 )
119
120
cfg = read (path_to_config_file , loader = yaml .load )
120
121
121
122
# Copy all the pip dependencies required to run your code into a temporary
122
123
# folder then add the handler file in the root of this directory.
123
124
# Zip the contents of this folder into a single file and output to the dist
124
125
# 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 )
126
128
127
129
use_s3 = True
128
130
s3_file = upload_s3 (cfg , path_to_zip_file , use_s3 )
@@ -132,7 +134,7 @@ def deploy_s3(src, requirements=False, local_package=None):
132
134
create_function (cfg , path_to_zip_file , use_s3 , s3_file )
133
135
134
136
135
- def upload (src , requirements = False , local_package = None ):
137
+ def upload (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
136
138
"""Uploads a new function to AWS S3.
137
139
138
140
:param str src:
@@ -143,19 +145,20 @@ def upload(src, requirements=False, local_package=None):
143
145
well (and/or is not available on PyPi)
144
146
"""
145
147
# 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 )
147
149
cfg = read (path_to_config_file , loader = yaml .load )
148
150
149
151
# Copy all the pip dependencies required to run your code into a temporary
150
152
# folder then add the handler file in the root of this directory.
151
153
# Zip the contents of this folder into a single file and output to the dist
152
154
# 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 )
154
157
155
158
upload_s3 (cfg , path_to_zip_file )
156
159
157
160
158
- def invoke (src , alt_event = None , verbose = False ):
161
+ def invoke (src , event_file = 'event.json' , config_file = 'config.yaml' , verbose = False ):
159
162
"""Simulates a call to your function.
160
163
161
164
:param str src:
@@ -167,7 +170,7 @@ def invoke(src, alt_event=None, verbose=False):
167
170
Whether to print out verbose details.
168
171
"""
169
172
# 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 )
171
174
cfg = read (path_to_config_file , loader = yaml .load )
172
175
173
176
# Load environment variables from the config file into the actual
@@ -178,10 +181,7 @@ def invoke(src, alt_event=None, verbose=False):
178
181
os .environ [key ] = value
179
182
180
183
# 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 )
185
185
event = read (path_to_event_file , loader = json .loads )
186
186
187
187
# Tweak to allow module to import local modules
@@ -229,7 +229,7 @@ def init(src, minimal=False):
229
229
copy (dest_path , src )
230
230
231
231
232
- def build (src , requirements = False , local_package = None ):
232
+ def build (src , config_file = 'config.yaml' , requirements = False , local_package = None ):
233
233
"""Builds the file bundle.
234
234
235
235
:param str src:
@@ -240,7 +240,7 @@ def build(src, requirements=False, local_package=None):
240
240
well (and/or is not available on PyPi)
241
241
"""
242
242
# 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 )
244
244
cfg = read (path_to_config_file , loader = yaml .load )
245
245
246
246
# 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):
296
296
if os .path .isfile (filename ):
297
297
if filename == '.DS_Store' :
298
298
continue
299
- if filename == 'config.yaml' :
299
+ if filename == config_file :
300
300
continue
301
301
print ('Bundling: %r' % filename )
302
302
files .append (os .path .join (src , filename ))
0 commit comments