Skip to content

Commit

Permalink
added cli option to preserve VPC settings on update
Browse files Browse the repository at this point in the history
  • Loading branch information
gmyers-amfam committed Jun 13, 2018
1 parent 7afe7cf commit 2e0831a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
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)
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

0 comments on commit 2e0831a

Please sign in to comment.