Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ target/
# vim swap files
.*.sw?
aws_lambda/.DS_Store
.DS_Store
.DS_Store
.vscode/
26 changes: 22 additions & 4 deletions aws_lambda/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@


ARN_PREFIXES = {
'cn-north-1': 'aws-cn',
'cn-northwest-1': 'aws-cn',
'us-gov-west-1': 'aws-us-gov',
}

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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': {
Expand All @@ -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': {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions aws_lambda/project_templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ aws_secret_access_key:
# dist_directory: dist
# timeout: 15
# memory_size: 512
# concurrency: 500
#

# Experimental Environment variables
Expand Down