Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for environment_variables config option #273

Merged
merged 3 commits into from
Apr 3, 2017

Conversation

jamesls
Copy link
Member

@jamesls jamesls commented Apr 3, 2017

These changes include:

This builds on the initial work from @emellis (#243) and adds
support for the environment variables config option.

  • Updating the config object with an environment_variables property
  • Adding the concept of "chain merge" to config. This allows
    a dict to be updated (merged) instead of returning on the first value
    found.
  • Update API based deployer to inject env vars when needed. This is
    needed for both create_function and update_function calls.
  • Changed update_function_code to just update_function which will
    optionally update function config if required
  • Update packager to add environment variables to SAM template.

NOTE: This doesn't merge cleanly on the package branch, and I based
it off the latest PR (#272). The only commit you need to review here
is the latest commit: jamesls@507dd11

@codecov-io
Copy link

codecov-io commented Apr 3, 2017

Codecov Report

Merging #273 into package will increase coverage by 0.68%.
The diff coverage is 96.96%.

Impacted file tree graph

@@             Coverage Diff             @@
##           package     #273      +/-   ##
===========================================
+ Coverage    85.87%   86.55%   +0.68%     
===========================================
  Files           18       18              
  Lines         1678     1696      +18     
  Branches       202      207       +5     
===========================================
+ Hits          1441     1468      +27     
+ Misses         184      175       -9     
  Partials        53       53
Impacted Files Coverage Δ
chalice/package.py 97.05% <100%> (+0.08%) ⬆️
chalice/cli/__init__.py 74.85% <100%> (ø) ⬆️
chalice/awsclient.py 82.99% <100%> (+0.85%) ⬆️
chalice/deploy/deployer.py 78.86% <100%> (+5.01%) ⬆️
chalice/config.py 96.42% <90%> (-0.87%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e456a1...25ca060. Read the comment docs.

FunctionName=function_name, ZipFile=zip_contents)
if environment_variables is not None:
Copy link

@emellis emellis Apr 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this code sits currently won't delete environment variables if the user removes all references to it from their config file. I think it makes sense to have the deployment reflect the config as much as possible. Maybe use something like the following if this is functionality that you want.

if not environment_variables:
    environment_variables = {}
lambda_client.update_function_configuration(
    FunctionName=function_name,
    Environment={"Variables": environment_variables})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emellis that makes sense to me as well. The one downside of doing this is that the UpdateFunctionConfiguration operation will be called every time even when no environment variables were configured. @jamesls is there any other downsides with this approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I was hoping to avoid calling update_function_configuration unless needed, I think it's best to just call it every time. Otherwise I'd have to store previously deployed function config values which I'd prefer not to do (I plan on adding support for all the various lambda config options, just wanted to start with environment_variables to make sure there were no issues)

It is an extra function call, but I don't think it will slow things down too much.

I'll get this updated.

Copy link
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. Think we should resolve the point @emellis pointed out before merging.

jamesls added 2 commits April 4, 2017 06:26
This builds on the initial work from @emellis and adds
support for the environment variables config option.

These changes include:

* Updating the config object with an environment_variables property
* Adding the concept of "chain merge" to config.  This allows
a dict to be updated (merged) instead of returning on the first value
found.
* Update API based deployer to inject env vars when needed.  This is
needed for both create_function and update_function calls.
* Changed update_function_code to just update_function which will
optionally update function config if required
* Update packager to add environment variables to SAM template.

There's still a few things in the initial PR that I'll need to circle
back on in follow up PRs.
Handle the case where a user completely removes the env vars
from their config.json.  We'll need this as more config options
for lambda are added.
@jamesls
Copy link
Member Author

jamesls commented Apr 3, 2017

Updated accordingly, should be ready for another look. I also rebased against the latest package branch so the diff should be easier to read.

Copy link
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a small comment. 🚢

@@ -25,8 +25,11 @@ def test_deploy_rest_api(stubbed_session):


def test_update_function_code_only(stubbed_session):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably will want to update the test name now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants