From 7ac89a682168bb3ddc071a7cdab6454ece446982 Mon Sep 17 00:00:00 2001 From: Jay Bredenberg Date: Sun, 11 Sep 2016 22:47:43 -0400 Subject: [PATCH 1/5] 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 --- aws_lambda/aws_lambda.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/aws_lambda/aws_lambda.py b/aws_lambda/aws_lambda.py index 612484ed..cde867c2 100755 --- a/aws_lambda/aws_lambda.py +++ b/aws_lambda/aws_lambda.py @@ -129,8 +129,12 @@ def build(src, local_package=None): function_name = cfg.get('function_name') output_filename = "{0}-{1}.zip".format(timestamp(), function_name) + # Handle if we needed to add an "extra-index-url" to our requirements file + # to successfully download required packages. + extra_index_url = cfg.get('extra_index_url', None) + path_to_temp = mkdtemp(prefix='aws-lambda') - pip_install_to_target(path_to_temp, local_package) + pip_install_to_target(path_to_temp, local_package, extra_index_url) # Gracefully handle whether ".zip" was included in the filename or not. output_filename = ('{0}.zip'.format(output_filename) @@ -191,7 +195,7 @@ def get_handler_filename(handler): return '{0}.py'.format(module_name) -def pip_install_to_target(path, local_package=None): +def pip_install_to_target(path, local_package=None, extra_index_url=None): """For a given active virtualenv, gather all installed pip packages then copy (re-install) them to the path provided. @@ -210,7 +214,13 @@ def pip_install_to_target(path, local_package=None): r = r.replace('-e ','') print('Installing {package}'.format(package=r)) - pip.main(['install', r, '-t', path, '--ignore-installed']) + pip_command_arguments = ['install', r, '-t', path, '--ignore-installed'] + + # Add optional pip arguments (--extra-index-url) to the base pip command + if extra_index_url is not None and extra_index_url != '': + pip_command_arguments += ['--extra-index-url', extra_index_url] + + pip.main(pip_command_arguments) if local_package is not None: pip.main(['install', local_package, '-t', path]) From 77659619a102cb474466facf11147dab312b39ce Mon Sep 17 00:00:00 2001 From: Jay Bredenberg Date: Sun, 11 Sep 2016 23:01:51 -0400 Subject: [PATCH 2/5] Adding entries for lambda role and pip's 'extra-index-url' to the config template --- aws_lambda/project_template/config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aws_lambda/project_template/config.yaml b/aws_lambda/project_template/config.yaml index 7f39794d..76cace03 100644 --- a/aws_lambda/project_template/config.yaml +++ b/aws_lambda/project_template/config.yaml @@ -10,6 +10,11 @@ description: My first lambda function aws_access_key_id: aws_secret_access_key: +# Lambda Configuration Settings +# role: lambda_basic_execution # dist_directory: dist # timeout: 15 # memory_size: 512 + +# (Optional) Pip Settings +# extra_index_url: From d08efe292d28be13bcba6df979fcc1399e717669 Mon Sep 17 00:00:00 2001 From: Jay Bredenberg Date: Sun, 11 Sep 2016 23:02:21 -0400 Subject: [PATCH 3/5] Updating the requirements to match the install version so that the lambda script will run --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 959eed00..06289851 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,6 @@ futures==3.0.5 jmespath==0.9.0 pyaml==15.8.2 python-dateutil==2.5.3 -python-lambda==0.2.0 +python-lambda==0.4.0 PyYAML==3.11 six==1.10.0 \ No newline at end of file From 837b2461aa74988f306bf3e3fa04bf0d1f10bca1 Mon Sep 17 00:00:00 2001 From: Jay Bredenberg Date: Tue, 21 Mar 2017 23:09:24 -0400 Subject: [PATCH 4/5] Updating to the latest boto3/botocore to get past some issues deploying lambda --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 683f1951..a1ec6fca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -boto3==1.4.1 -botocore==1.4.61 +boto3==1.4.4 +botocore==1.5.27 click==6.6 docutils==0.12 futures==3.0.5 From 3b688ba4a7db71f2b42d7dbb3eb850336627d900 Mon Sep 17 00:00:00 2001 From: Jay Bredenberg Date: Wed, 22 Mar 2017 00:39:22 -0400 Subject: [PATCH 5/5] Modifying the function_exists() call as it seems to not be catching recently installed lambda functions. by calling get_function() instead of list_functions... it seems to work. --- aws_lambda/aws_lambda.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aws_lambda/aws_lambda.py b/aws_lambda/aws_lambda.py index bb65869e..3dc62a3e 100755 --- a/aws_lambda/aws_lambda.py +++ b/aws_lambda/aws_lambda.py @@ -367,8 +367,8 @@ def function_exists(cfg, function_name): aws_secret_access_key = cfg.get('aws_secret_access_key') client = get_client('lambda', aws_access_key_id, aws_secret_access_key, cfg.get('region')) - functions = client.list_functions().get('Functions', []) - for fn in functions: - if fn.get('FunctionName') == function_name: - return True - return False + try: + client.get_function(FunctionName=function_name) + return True + except botocore.errorfactory.ResourceNotFoundException as e: + return False