@@ -109,8 +109,9 @@ def deploy(
109
109
local_package = local_package ,
110
110
)
111
111
112
- if function_exists (cfg ):
113
- update_function (cfg , path_to_zip_file )
112
+ existing_config = get_function_config (cfg )
113
+ if existing_config :
114
+ update_function (cfg , path_to_zip_file , existing_config )
114
115
else :
115
116
create_function (cfg , path_to_zip_file )
116
117
@@ -143,8 +144,10 @@ def deploy_s3(
143
144
144
145
use_s3 = True
145
146
s3_file = upload_s3 (cfg , path_to_zip_file , use_s3 )
146
- if function_exists (cfg ):
147
- update_function (cfg , path_to_zip_file , use_s3 = use_s3 , s3_file = s3_file )
147
+ existing_config = get_function_config (cfg )
148
+ if existing_config :
149
+ update_function (cfg , path_to_zip_file , existing_config , use_s3 = use_s3 ,
150
+ s3_file = s3_file )
148
151
else :
149
152
create_function (cfg , path_to_zip_file , use_s3 = use_s3 , s3_file = s3_file )
150
153
@@ -538,6 +541,14 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
538
541
'Publish' : True ,
539
542
}
540
543
544
+ if 'tags' in cfg :
545
+ kwargs .update (
546
+ Tags = {
547
+ key : str (value )
548
+ for key , value in cfg .get ('tags' ).items ()
549
+ }
550
+ )
551
+
541
552
if 'environment_variables' in cfg :
542
553
kwargs .update (
543
554
Environment = {
@@ -552,7 +563,9 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
552
563
client .create_function (** kwargs )
553
564
554
565
555
- def update_function (cfg , path_to_zip_file , use_s3 = False , s3_file = None ):
566
+ def update_function (
567
+ cfg , path_to_zip_file , existing_cfg , use_s3 = False , s3_file = None
568
+ ):
556
569
"""Updates the code of an existing Lambda function"""
557
570
558
571
print ('Updating your Lambda function' )
@@ -620,7 +633,18 @@ def update_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
620
633
},
621
634
)
622
635
623
- client .update_function_configuration (** kwargs )
636
+ ret = client .update_function_configuration (** kwargs )
637
+
638
+ if 'tags' in cfg :
639
+ tags = {
640
+ key : str (value )
641
+ for key , value in cfg .get ('tags' ).items ()
642
+ }
643
+ if tags != existing_cfg .get ('Tags' ):
644
+ if existing_cfg .get ('Tags' ):
645
+ client .untag_resource (Resource = ret ['FunctionArn' ],
646
+ TagKeys = list (existing_cfg ['Tags' ].keys ()))
647
+ client .tag_resource (Resource = ret ['FunctionArn' ], Tags = tags )
624
648
625
649
626
650
def upload_s3 (cfg , path_to_zip_file , * use_s3 ):
@@ -663,8 +687,8 @@ def upload_s3(cfg, path_to_zip_file, *use_s3):
663
687
return filename
664
688
665
689
666
- def function_exists (cfg ):
667
- """Check whether a function exists or not"""
690
+ def get_function_config (cfg ):
691
+ """Check whether a function exists or not and return its config """
668
692
669
693
function_name = cfg .get ('function_name' )
670
694
profile_name = cfg .get ('profile' )
@@ -681,6 +705,7 @@ def function_exists(cfg):
681
705
if 'Function not found' in str (e ):
682
706
return False
683
707
708
+
684
709
def read_cfg (path_to_config_file , profile_name ):
685
710
cfg = read (path_to_config_file , loader = yaml .load )
686
711
if profile_name is not None :
0 commit comments