2828
2929
3030ARN_PREFIXES = {
31+ 'cn-north-1' : 'aws-cn' ,
32+ 'cn-northwest-1' : 'aws-cn' ,
3133'us-gov-west-1' : 'aws-us-gov' ,
3234}
3335
@@ -434,7 +436,7 @@ def pip_install_to_target(path, requirements=None, local_package=None):
434436packages = []
435437if not requirements :
436438print ('Gathering pip packages' )
437- pkgStr = subprocess .check_call ([sys .executable , '-m' , 'pip' , 'freeze' ])
439+ pkgStr = subprocess .check_output ([sys .executable , '-m' , 'pip' , 'freeze' ])
438440packages .extend (pkgStr .decode ('utf-8' ).splitlines ())
439441else :
440442if os .path .exists (requirements ):
@@ -529,7 +531,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
529531'S3Bucket' : '{}' .format (buck_name ),
530532'S3Key' : '{}' .format (s3_file ),
531533 },
532- 'Description' : cfg .get ('description' ),
534+ 'Description' : cfg .get ('description' , '' ),
533535'Timeout' : cfg .get ('timeout' , 15 ),
534536'MemorySize' : cfg .get ('memory_size' , 512 ),
535537'VpcConfig' :{
@@ -545,7 +547,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
545547'Role' : role ,
546548'Handler' : cfg .get ('handler' ),
547549'Code' :{'ZipFile' : byte_stream },
548- 'Description' : cfg .get ('description' ),
550+ 'Description' : cfg .get ('description' , '' ),
549551'Timeout' : cfg .get ('timeout' , 15 ),
550552'MemorySize' : cfg .get ('memory_size' , 512 ),
551553'VpcConfig' :{
@@ -576,6 +578,10 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
576578
577579client .create_function (** kwargs )
578580
581+ concurrency = get_concurrency (cfg )
582+ if concurrency > 0 :
583+ client .put_function_concurrency (FunctionName = func_name , ReservedConcurrentExecutions = concurrency )
584+
579585
580586def update_function (
581587cfg , path_to_zip_file , existing_cfg , use_s3 = False , s3_file = None , preserve_vpc = False
@@ -627,7 +633,7 @@ def update_function(
627633'Role' : role ,
628634'Runtime' : cfg .get ('runtime' ),
629635'Handler' : cfg .get ('handler' ),
630- 'Description' : cfg .get ('description' ),
636+ 'Description' : cfg .get ('description' , '' ),
631637'Timeout' : cfg .get ('timeout' , 15 ),
632638'MemorySize' : cfg .get ('memory_size' , 512 ),
633639 }
@@ -660,6 +666,12 @@ def update_function(
660666
661667ret = client .update_function_configuration (** kwargs )
662668
669+ concurrency = get_concurrency (cfg )
670+ if concurrency > 0 :
671+ client .put_function_concurrency (FunctionName = cfg .get ('function_name' ), ReservedConcurrentExecutions = concurrency )
672+ elif 'Concurrency' in existing_cfg :
673+ client .delete_function_concurrency (FunctionName = cfg .get ('function_name' ))
674+
663675if 'tags' in cfg :
664676tags = {
665677key : str (value )
@@ -731,6 +743,12 @@ def get_function_config(cfg):
731743return False
732744
733745
746+ def get_concurrency (cfg ):
747+ """Return the Reserved Concurrent Executions if present in the config"""
748+ concurrency = int (cfg .get ('concurrency' , 0 ))
749+ return max (0 , concurrency )
750+
751+
734752def read_cfg (path_to_config_file , profile_name ):
735753cfg = read (path_to_config_file , loader = yaml .load )
736754if profile_name is not None :
0 commit comments