-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
21286dc
Add VPC support
bfe2ede
Put back original linter values
jamesls 43e68de
Security groups vary per function
jamesls 960d9a1
Flesh out the rest of the deployer
jamesls f676492
Remove unused ApplicationPolicyHandler
jamesls e588e4d
Update docs with more config examples
jamesls 3faa8de
Add feature to changelog
jamesls a7cd61e
Add a reference back to the stage config in the lambda config
jamesls 5e24f5e
Extract validate tests into separate module
jamesls 7688312
Raise validation error on invalid VPC params
jamesls 3c1f3c7
Retry lambda errors related to VPC permissions
jamesls 30ba203
Remove unused ifcheck, not needed
jamesls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ | |
RequestsConnectionError | ||
from botocore.session import Session # noqa | ||
import jmespath | ||
from typing import Optional, Dict, List, Any, Set, cast # noqa | ||
from typing import Optional, Dict, List, Any, Set, Tuple, cast # noqa | ||
|
||
from chalice import app | ||
from chalice.config import Config # noqa | ||
|
@@ -231,6 +231,10 @@ def _get_mb(self, value): | |
return '%.1f MB' % (float(value) / (1024 ** 2)) | ||
|
||
|
||
class ChaliceBuildError(Exception): | ||
pass | ||
|
||
|
||
def create_default_deployer(session, config, ui): | ||
# type: (Session, Config, UI) -> Deployer | ||
client = TypedAWSClient(session) | ||
|
@@ -547,6 +551,24 @@ def _create_role_reference(self, config, stage_name, function_name): | |
policy=policy, | ||
) | ||
|
||
def _get_vpc_params(self, function_name, config): | ||
# type: (str, Config) -> Tuple[List[str], List[str]] | ||
security_group_ids = config.security_group_ids | ||
subnet_ids = config.subnet_ids | ||
if security_group_ids and subnet_ids: | ||
return security_group_ids, subnet_ids | ||
elif not security_group_ids and not subnet_ids: | ||
return [], [] | ||
else: | ||
raise ChaliceBuildError( | ||
"Invalid VPC params for function '%s', in order to configure " | ||
"VPC for a Lambda function, you must provide the subnet_ids " | ||
"as well as the security_group_ids, got subnet_ids: %s, " | ||
"security_group_ids: %s" % (function_name, | ||
subnet_ids, | ||
security_group_ids) | ||
) | ||
|
||
def _build_lambda_function(self, | ||
config, # type: Config | ||
name, # type: str | ||
|
@@ -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 commentThe 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 |
||
security_group_ids = [] | ||
subnet_ids = [] | ||
security_group_ids, subnet_ids = self._get_vpc_params(name, config) | ||
function = models.LambdaFunction( | ||
resource_name=name, | ||
function_name=function_name, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.