@@ -85,6 +85,7 @@ def cleanup_old_versions(
8585def deploy (
8686 src , requirements = None , local_package = None ,
8787 config_file = 'config.yaml' , profile_name = None ,
88+ preserve_vpc = False
8889):
8990 """Deploys a new function to AWS Lambda.
9091
@@ -111,14 +112,15 @@ def deploy(
111112
112113 existing_config = get_function_config (cfg )
113114 if existing_config :
114- update_function (cfg , path_to_zip_file , existing_config )
115+ update_function (cfg , path_to_zip_file , existing_config , preserve_vpc )
115116 else :
116117 create_function (cfg , path_to_zip_file )
117118
118119
119120def deploy_s3 (
120121 src , requirements = None , local_package = None ,
121122 config_file = 'config.yaml' , profile_name = None ,
123+ preserve_vpc = False
122124):
123125 """Deploys a new function via AWS S3.
124126
@@ -147,7 +149,7 @@ def deploy_s3(
147149 existing_config = get_function_config (cfg )
148150 if existing_config :
149151 update_function (cfg , path_to_zip_file , existing_config , use_s3 = use_s3 ,
150- s3_file = s3_file )
152+ s3_file = s3_file , preserve_vpc = preserve_vpc )
151153 else :
152154 create_function (cfg , path_to_zip_file , use_s3 = use_s3 , s3_file = s3_file )
153155
@@ -580,7 +582,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
580582
581583
582584def update_function (
583- cfg , path_to_zip_file , existing_cfg , use_s3 = False , s3_file = None
585+ cfg , path_to_zip_file , existing_cfg , use_s3 = False , s3_file = None , preserve_vpc = False
584586):
585587 """Updates the code of an existing Lambda function"""
586588
@@ -632,11 +634,15 @@ def update_function(
632634 'Description' : cfg .get ('description' ),
633635 'Timeout' : cfg .get ('timeout' , 15 ),
634636 'MemorySize' : cfg .get ('memory_size' , 512 ),
635- 'VpcConfig' : {
637+ }
638+
639+ if preserve_vpc :
640+ kwargs ['VpcConfig' ] = existing_cfg .get ('VpcConfig' )
641+ else :
642+ kwargs ['VpcConfig' ] = {
636643 'SubnetIds' : cfg .get ('subnet_ids' , []),
637644 'SecurityGroupIds' : cfg .get ('security_group_ids' , []),
638- },
639- }
645+ }
640646
641647 if 'environment_variables' in cfg :
642648 kwargs .update (
0 commit comments