@@ -85,6 +85,7 @@ def cleanup_old_versions(
85
85
def deploy (
86
86
src , requirements = None , local_package = None ,
87
87
config_file = 'config.yaml' , profile_name = None ,
88
+ preserve_vpc = False
88
89
):
89
90
"""Deploys a new function to AWS Lambda.
90
91
@@ -111,14 +112,15 @@ def deploy(
111
112
112
113
existing_config = get_function_config (cfg )
113
114
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 )
115
116
else :
116
117
create_function (cfg , path_to_zip_file )
117
118
118
119
119
120
def deploy_s3 (
120
121
src , requirements = None , local_package = None ,
121
122
config_file = 'config.yaml' , profile_name = None ,
123
+ preserve_vpc = False
122
124
):
123
125
"""Deploys a new function via AWS S3.
124
126
@@ -147,7 +149,7 @@ def deploy_s3(
147
149
existing_config = get_function_config (cfg )
148
150
if existing_config :
149
151
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 )
151
153
else :
152
154
create_function (cfg , path_to_zip_file , use_s3 = use_s3 , s3_file = s3_file )
153
155
@@ -580,7 +582,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
580
582
581
583
582
584
def 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
584
586
):
585
587
"""Updates the code of an existing Lambda function"""
586
588
@@ -632,11 +634,15 @@ def update_function(
632
634
'Description' : cfg .get ('description' ),
633
635
'Timeout' : cfg .get ('timeout' , 15 ),
634
636
'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' ] = {
636
643
'SubnetIds' : cfg .get ('subnet_ids' , []),
637
644
'SecurityGroupIds' : cfg .get ('security_group_ids' , []),
638
- },
639
- }
645
+ }
640
646
641
647
if 'environment_variables' in cfg :
642
648
kwargs .update (
0 commit comments