-
Notifications
You must be signed in to change notification settings - Fork 1k
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 VPC support to lambda functions #837
Conversation
Had to do some minor refactoring to get things passing.
This was an artifact of the old deployer.
Codecov Report
@@ Coverage Diff @@
## master #837 +/- ##
=========================================
+ Coverage 94.79% 94.8% +0.01%
=========================================
Files 21 21
Lines 3707 3735 +28
Branches 478 486 +8
=========================================
+ Hits 3514 3541 +27
Misses 130 130
- Partials 63 64 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me, just a few questions.
@@ -11,6 +11,7 @@ CHANGELOG | |||
* Update ``policies.json`` file | |||
(`#817 <https://github.com/aws/chalice/issues/817>`__) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a changelog entry
will be applied to that function. These are the configuration options | ||
that can be applied per function: | ||
|
||
* ``iam_policy_file`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to have their default values listed somewhere if they are omitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a reference back to the stage config, these are described in the section above.
resource.document = self._policy_gen.generate_policy(config) | ||
policy = self._policy_gen.generate_policy(config) | ||
if models.RoleTraits.VPC_NEEDED in resource.traits: | ||
policy['Statement'].append(VPC_ATTACH_POLICY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about replacing the *
in VPC_ATTACH_POLICY resources section with all the specific ARNs from the config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're different ARNs. The config ARNs are for the subnet/sg ids, but the VPC policy is to CRUD ENIs.
6d6cdab
to
a7cd61e
Compare
@stealthycoin Feedback incorporated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A couple of things that I ran into while playing around with this. I may have some more...
-
We should add validation that both
subnet_ids
andsecurity_group_ids
are present in the config. Otherwise,chalice
will it ignore it and deploy the lambda function without letting the user know about the issue. -
Trying it out I think there is an eventual consistency issue where: if you deploy the lambda function once (with no VPC configured), and then again (waiting a minute or so) it will error out with the following error:
ChaliceDeploymentError: ERROR - While deploying your chalice application, received the following error:
An error occurred (InvalidParameterValueException) when calling the
UpdateFunctionConfiguration operation: The provided execution role does not
have permissions to call CreateNetworkInterface on EC2
However running deploy again succeeds.
So (1) ends up being a little tricker than I thought and there's a number of edge cases. I was initially adding validation to the
Deploying to
but my actual app only has a
It doesn't seem like we should say the config is invalid because you I think what I'm going to do is just make this a deployer error. If we try to create a What do you think? |
This was initially done in chalice.deploy.validate, but it produces too many false positives. This way, we only fail if we try to construct a resource with invalid params. This does mean we might have latent issues that we'll only find about when we try to deploy our app, but that seems better than failing validation when it wouldn't actually affect a deploy.
@kyleknap feedback incorporated. I ended up just adding the validation in the AppGraphBuilder. That way you can catch the error with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just had a small comment and a follow up question. So if the validation errors were in chalice.deploy.validate
instead, what specific features would you get these false positives? Like is it related to getting an error when running chalice local
for these misconfigured stages/functions?
chalice/deploy/deployer.py
Outdated
@@ -559,9 +581,10 @@ def _build_lambda_function(self, | |||
config.app_name, config.chalice_stage, name) | |||
security_group_ids = config.security_group_ids | |||
subnet_ids = config.subnet_ids | |||
if security_group_ids is None or subnet_ids is None: | |||
if security_group_ids is None and subnet_ids is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this if statement still needed? It looks like it gets handled in _get_vpc_params
and is not necessarily needed.
@kyleknap The two examples I gave in my previous comments give you false positives. One was for an invalid stage that you're not deploying to and one was config for a non-existent function (defined in config but not in app). By false positive, I mean the "config validation" would fail, but if you actually were to somehow turn off validation and just let |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh that makes more sense. Besides that I had a comment that looks like it got hidden so I posted it again. Otherwise, 🚢
chalice/deploy/deployer.py
Outdated
@@ -555,7 +579,13 @@ def _build_lambda_function(self, | |||
# type: (...) -> models.LambdaFunction | |||
function_name = '%s-%s-%s' % ( | |||
config.app_name, config.chalice_stage, name) | |||
return models.LambdaFunction( | |||
security_group_ids = config.security_group_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned this before but I think we can remove lines 582-586 because they are handled in the _get_vpc_params()
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed now.
Thanks. 🚢 again |
PR #837 * lime-green-vpc-support: Remove unused ifcheck, not needed Retry lambda errors related to VPC permissions Raise validation error on invalid VPC params Extract validate tests into separate module Add a reference back to the stage config in the lambda config Add feature to changelog Update docs with more config examples Remove unused ApplicationPolicyHandler Flesh out the rest of the deployer Security groups vary per function Put back original linter values Add VPC support
This adds VPC support to lambda functions in chalice. It pulls in #673 and fleshes out the rest of the deployer support for VPC. Notably it makes a few changes:
traits
flag to theAutogenPolicy
which flags which policies it needs to add.This PR also triggered a few linter warnings so I cleaned up some of the code (as a separate commit). There was a whole class (with tests) that was no longer used. It was a part of the legacy deployer.
Thanks to @lime-green for the original PR.