Skip to content

Commit 7ac89a6

Browse files
committed
Adding support for pip installs with --extra-index-url that might be defined in a requirements.txt file. You can add a new entry in the config.yaml file 'extra_index_url' that will use that as we pip install all of the current packages for the project
1 parent defa8b9 commit 7ac89a6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

aws_lambda/aws_lambda.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ def build(src, local_package=None):
129129
function_name = cfg.get('function_name')
130130
output_filename = "{0}-{1}.zip".format(timestamp(), function_name)
131131

132+
# Handle if we needed to add an "extra-index-url" to our requirements file
133+
# to successfully download required packages.
134+
extra_index_url = cfg.get('extra_index_url', None)
135+
132136
path_to_temp = mkdtemp(prefix='aws-lambda')
133-
pip_install_to_target(path_to_temp, local_package)
137+
pip_install_to_target(path_to_temp, local_package, extra_index_url)
134138

135139
# Gracefully handle whether ".zip" was included in the filename or not.
136140
output_filename = ('{0}.zip'.format(output_filename)
@@ -191,7 +195,7 @@ def get_handler_filename(handler):
191195
return '{0}.py'.format(module_name)
192196

193197

194-
def pip_install_to_target(path, local_package=None):
198+
def pip_install_to_target(path, local_package=None, extra_index_url=None):
195199
"""For a given active virtualenv, gather all installed pip packages then
196200
copy (re-install) them to the path provided.
197201
@@ -210,7 +214,13 @@ def pip_install_to_target(path, local_package=None):
210214
r = r.replace('-e ','')
211215

212216
print('Installing {package}'.format(package=r))
213-
pip.main(['install', r, '-t', path, '--ignore-installed'])
217+
pip_command_arguments = ['install', r, '-t', path, '--ignore-installed']
218+
219+
# Add optional pip arguments (--extra-index-url) to the base pip command
220+
if extra_index_url is not None and extra_index_url != '':
221+
pip_command_arguments += ['--extra-index-url', extra_index_url]
222+
223+
pip.main(pip_command_arguments)
214224

215225
if local_package is not None:
216226
pip.main(['install', local_package, '-t', path])

0 commit comments

Comments
 (0)