1818log = logging .getLogger (__name__ )
1919
2020
21- def deploy (src ):
21+ def deploy (src , local_package = None ):
2222 """Deploys a new function to AWS Lambda.
2323
2424 :param str src:
2525 The path to your Lambda ready project (folder must contain a valid
2626 config.yaml and handler module (e.g.: service.py).
27+ :param str local_package:
28+ The path to a local package with should be included in the deploy as
29+ well (and/or is not available on PyPi)
2730 """
2831 # Load and parse the config file.
2932 path_to_config_file = os .path .join (src , 'config.yaml' )
@@ -33,7 +36,7 @@ def deploy(src):
3336 # folder then add the handler file in the root of this directory.
3437 # Zip the contents of this folder into a single file and output to the dist
3538 # directory.
36- path_to_zip_file = build (src )
39+ path_to_zip_file = build (src , local_package )
3740
3841 if function_exists (cfg , cfg .get ('function_name' )):
3942 update_function (cfg , path_to_zip_file )
@@ -101,15 +104,15 @@ def init(src, minimal=False):
101104 copy (path_to_file , src )
102105
103106
104- def build (src ):
107+ def build (src , local_package = None ):
105108 """Builds the file bundle.
106109
107- :param str path_to_handler_file :
108- The path to handler (main execution) file.
109- :param str path_to_dist:
110- The path to the folder for distributable.
111- :param str output_filename:
112- The name of the archive file.
110+ :param str src :
111+ The path to your Lambda ready project (folder must contain a valid
112+ config.yaml and handler module (e.g.: service.py).
113+ :param str local_package:
114+ The path to a local package with should be included in the deploy as
115+ well (and/or is not available on PyPi)
113116 """
114117 # Load and parse the config file.
115118 path_to_config_file = os .path .join (src , 'config.yaml' )
@@ -127,7 +130,7 @@ def build(src):
127130 output_filename = "{0}-{1}.zip" .format (timestamp (), function_name )
128131
129132 path_to_temp = mkdtemp (prefix = 'aws-lambda' )
130- pip_install_to_target (path_to_temp )
133+ pip_install_to_target (path_to_temp , local_package )
131134
132135 # Gracefully handle whether ".zip" was included in the filename or not.
133136 output_filename = ('{0}.zip' .format (output_filename )
@@ -188,24 +191,30 @@ def get_handler_filename(handler):
188191 return '{0}.py' .format (module_name )
189192
190193
191- def pip_install_to_target (path ):
194+ def pip_install_to_target (path , local_package = None ):
192195 """For a given active virtualenv, gather all installed pip packages then
193196 copy (re-install) them to the path provided.
194197
195198 :param str path:
196199 Path to copy installed pip packages to.
200+ :param str local_package:
201+ The path to a local package with should be included in the deploy as
202+ well (and/or is not available on PyPi)
197203 """
198204 print ('Gathering pip packages' )
199205 for r in pip .operations .freeze .freeze ():
200- if r .startswith ('Python==' ):
206+ if r .startswith ('Python==' ) or r . startswith ( '-e git+git' ) :
201207 # For some reason Python is coming up in pip freeze.
202208 continue
203209 pip .main (['install' , r , '-t' , path , '--ignore-installed' ])
204210
211+ if local_package is not None :
212+ pip .main (['install' , local_package , '-t' , path ])
213+
205214
206- def get_role_name (account_id ):
207- """Shortcut to insert the `account_id` into the iam string."""
208- return "arn:aws:iam::{0}:role/lambda_basic_execution " .format (account_id )
215+ def get_role_name (account_id , role ):
216+ """Shortcut to insert the `account_id` and `role` into the iam string."""
217+ return "arn:aws:iam::{0}:role/{1} " .format (account_id , role )
209218
210219
211220def get_account_id (aws_access_key_id , aws_secret_access_key ):
@@ -234,7 +243,7 @@ def create_function(cfg, path_to_zip_file):
234243 aws_secret_access_key = cfg .get ('aws_secret_access_key' )
235244
236245 account_id = get_account_id (aws_access_key_id , aws_secret_access_key )
237- role = get_role_name (account_id )
246+ role = get_role_name (account_id , cfg . get ( 'role' , 'lambda_basic_execution' ) )
238247
239248 client = get_client ('lambda' , aws_access_key_id , aws_secret_access_key ,
240249 cfg .get ('region' ))
0 commit comments