Skip to content

Commit d85a35d

Browse files
authored
Merge pull request nficano#129 from soapergem/master
fixes for nficano#128 and nficano#104 and nficano#103
2 parents 7266d1a + e02c3dc commit d85a35d

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ target/
6464
# vim swap files
6565
.*.sw?
6666
aws_lambda/.DS_Store
67-
.DS_Store
67+
.DS_Store
68+
.vscode/

aws_lambda/aws_lambda.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929

3030
ARN_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):
434436
packages = []
435437
if not requirements:
436438
print('Gathering pip packages')
437-
pkgStr = subprocess.check_call([sys.executable, '-m', 'pip', 'freeze'])
439+
pkgStr = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
438440
packages.extend(pkgStr.decode('utf-8').splitlines())
439441
else:
440442
if 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

577579
client.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

580586
def update_function(
581587
cfg, 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

661667
ret = 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+
663675
if 'tags' in cfg:
664676
tags = {
665677
key: str(value)
@@ -731,6 +743,12 @@ def get_function_config(cfg):
731743
return 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+
734752
def read_cfg(path_to_config_file, profile_name):
735753
cfg = read(path_to_config_file, loader=yaml.load)
736754
if profile_name is not None:

aws_lambda/project_templates/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ aws_secret_access_key:
1919
# dist_directory: dist
2020
# timeout: 15
2121
# memory_size: 512
22+
# concurrency: 500
2223
#
2324

2425
# Experimental Environment variables

0 commit comments

Comments
 (0)