Skip to content

Commit 86343eb

Browse files
committed
Merge pull request nficano#7 from quiqua/local_package
Add option to install a local package to be deployed as well
2 parents 70931cd + 6552bdb commit 86343eb

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

aws_lambda/aws_lambda.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
log = 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,20 +191,26 @@ 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

206215
def get_role_name(account_id, role):
207216
"""Shortcut to insert the `account_id` and `role` into the iam string."""

scripts/lambda

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def init():
2121

2222

2323
@click.command(help="Bundles package for deployment.")
24-
def build():
25-
aws_lambda.build(CURRENT_DIR)
24+
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path())
25+
def build(local_package):
26+
aws_lambda.build(CURRENT_DIR, local_package)
2627

2728

2829
@click.command(help="Run a local test of your function.")
@@ -33,8 +34,9 @@ def invoke(event_file, verbose):
3334

3435

3536
@click.command(help="Register and deploy your code to lambda.")
36-
def deploy():
37-
aws_lambda.deploy(CURRENT_DIR)
37+
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path())
38+
def deploy(local_package):
39+
aws_lambda.deploy(CURRENT_DIR, local_package)
3840

3941
if __name__ == '__main__':
4042
cli.add_command(init)

0 commit comments

Comments
 (0)