Skip to content
This repository was archived by the owner on Mar 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added cli option to preserve VPC settings on update
  • Loading branch information
gmyers-amfam committed Jun 13, 2018
commit 2e0831a1472264ce6b86e674291bf3d1dc65ecfe
18 changes: 12 additions & 6 deletions aws_lambda/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def cleanup_old_versions(
def deploy(
src, requirements=None, local_package=None,
config_file='config.yaml', profile_name=None,
preserve_vpc=False
):
"""Deploys a new function to AWS Lambda.

Expand All @@ -111,14 +112,15 @@ def deploy(

existing_config = get_function_config(cfg)
if existing_config:
update_function(cfg, path_to_zip_file, existing_config)
update_function(cfg, path_to_zip_file, existing_config, preserve_vpc)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Needs to pass preserve_vpc value as kwargs.

else:
create_function(cfg, path_to_zip_file)


def deploy_s3(
src, requirements=None, local_package=None,
config_file='config.yaml', profile_name=None,
preserve_vpc=False
):
"""Deploys a new function via AWS S3.

Expand Down Expand Up @@ -147,7 +149,7 @@ def deploy_s3(
existing_config = get_function_config(cfg)
if existing_config:
update_function(cfg, path_to_zip_file, existing_config, use_s3=use_s3,
s3_file=s3_file)
s3_file=s3_file, preserve_vpc=preserve_vpc)
else:
create_function(cfg, path_to_zip_file, use_s3=use_s3, s3_file=s3_file)

Expand Down Expand Up @@ -580,7 +582,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):


def update_function(
cfg, path_to_zip_file, existing_cfg, use_s3=False, s3_file=None
cfg, path_to_zip_file, existing_cfg, use_s3=False, s3_file=None, preserve_vpc=False
):
"""Updates the code of an existing Lambda function"""

Expand Down Expand Up @@ -632,11 +634,15 @@ def update_function(
'Description': cfg.get('description'),
'Timeout': cfg.get('timeout', 15),
'MemorySize': cfg.get('memory_size', 512),
'VpcConfig': {
}

if preserve_vpc:
kwargs['VpcConfig'] = existing_cfg.get('VpcConfig')
else:
kwargs['VpcConfig'] = {
'SubnetIds': cfg.get('subnet_ids', []),
'SecurityGroupIds': cfg.get('security_group_ids', []),
},
}
}

if 'environment_variables' in cfg:
kwargs.update(
Expand Down
9 changes: 8 additions & 1 deletion scripts/lambda
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,20 @@ def invoke(event_file, config_file, profile, verbose):
help='Install local package as well.',
multiple=True,
)
def deploy(requirements, local_package, config_file, profile):
@click.option(
'--preserve-vpc',
default=False,
is_flag=True,
help='Preserve VPC configuration on existing functions',
)
def deploy(requirements, local_package, config_file, profile, preserve_vpc):
aws_lambda.deploy(
CURRENT_DIR,
requirements=requirements,
local_package=local_package,
config_file=config_file,
profile_name=profile,
preserve_vpc=preserve_vpc,
)


Expand Down