diff --git a/.gitignore b/.gitignore index 840dfff..549d6f2 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ target/ # vim swap files .*.sw? aws_lambda/.DS_Store -.DS_Store \ No newline at end of file +.DS_Store +.vscode/ \ No newline at end of file diff --git a/aws_lambda/aws_lambda.py b/aws_lambda/aws_lambda.py index 9110518..0932934 100755 --- a/aws_lambda/aws_lambda.py +++ b/aws_lambda/aws_lambda.py @@ -28,6 +28,8 @@ ARN_PREFIXES = { + 'cn-north-1': 'aws-cn', + 'cn-northwest-1': 'aws-cn', 'us-gov-west-1': 'aws-us-gov', } @@ -434,7 +436,7 @@ def pip_install_to_target(path, requirements=None, local_package=None): packages = [] if not requirements: print('Gathering pip packages') - pkgStr = subprocess.check_call([sys.executable, '-m', 'pip', 'freeze']) + pkgStr = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) packages.extend(pkgStr.decode('utf-8').splitlines()) else: if os.path.exists(requirements): @@ -529,7 +531,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None): 'S3Bucket': '{}'.format(buck_name), 'S3Key': '{}'.format(s3_file), }, - 'Description': cfg.get('description'), + 'Description': cfg.get('description', ''), 'Timeout': cfg.get('timeout', 15), 'MemorySize': cfg.get('memory_size', 512), 'VpcConfig': { @@ -545,7 +547,7 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None): 'Role': role, 'Handler': cfg.get('handler'), 'Code': {'ZipFile': byte_stream}, - 'Description': cfg.get('description'), + 'Description': cfg.get('description', ''), 'Timeout': cfg.get('timeout', 15), 'MemorySize': cfg.get('memory_size', 512), 'VpcConfig': { @@ -576,6 +578,10 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None): client.create_function(**kwargs) + concurrency = get_concurrency(cfg) + if concurrency > 0: + client.put_function_concurrency(FunctionName=func_name, ReservedConcurrentExecutions=concurrency) + def update_function( cfg, path_to_zip_file, existing_cfg, use_s3=False, s3_file=None, preserve_vpc=False @@ -627,7 +633,7 @@ def update_function( 'Role': role, 'Runtime': cfg.get('runtime'), 'Handler': cfg.get('handler'), - 'Description': cfg.get('description'), + 'Description': cfg.get('description', ''), 'Timeout': cfg.get('timeout', 15), 'MemorySize': cfg.get('memory_size', 512), } @@ -660,6 +666,12 @@ def update_function( ret = client.update_function_configuration(**kwargs) + concurrency = get_concurrency(cfg) + if concurrency > 0: + client.put_function_concurrency(FunctionName=cfg.get('function_name'), ReservedConcurrentExecutions=concurrency) + elif 'Concurrency' in existing_cfg: + client.delete_function_concurrency(FunctionName=cfg.get('function_name')) + if 'tags' in cfg: tags = { key: str(value) @@ -731,6 +743,12 @@ def get_function_config(cfg): return False +def get_concurrency(cfg): + """Return the Reserved Concurrent Executions if present in the config""" + concurrency = int(cfg.get('concurrency', 0)) + return max(0, concurrency) + + def read_cfg(path_to_config_file, profile_name): cfg = read(path_to_config_file, loader=yaml.load) if profile_name is not None: diff --git a/aws_lambda/project_templates/config.yaml b/aws_lambda/project_templates/config.yaml index 8029c80..bc29371 100644 --- a/aws_lambda/project_templates/config.yaml +++ b/aws_lambda/project_templates/config.yaml @@ -19,6 +19,7 @@ aws_secret_access_key: # dist_directory: dist # timeout: 15 # memory_size: 512 +# concurrency: 500 # # Experimental Environment variables