Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 19 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=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,22 @@ 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('Configuration', {}).get('VpcConfig')
if kwargs['VpcConfig'] is None:
kwargs['VpcConfig'] = {
'SubnetIds': cfg.get('subnet_ids', []),
'SecurityGroupIds': cfg.get('security_group_ids', []),
}
else:
del kwargs['VpcConfig']['VpcId']
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