Skip to content

Commit 4390aeb

Browse files
committed
Issue: nficano#11, nficano#26 Environment variable support
create_function now has added support to create a lambda environment variables that are configured in the config.yaml file. Newer versions of botocore and boto3 are necessary to keep the create_function from complaining about the "Environment" dictionary key.
1 parent 26ad3de commit 4390aeb

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

aws_lambda/aws_lambda.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,29 +348,35 @@ def create_function(cfg, path_to_zip_file):
348348
client = get_client('lambda', aws_access_key_id, aws_secret_access_key,
349349
cfg.get('region'))
350350

351+
#Do we prefer development variable over config?
351352
func_name = (
352353
os.environ.get('LAMBDA_FUNCTION_NAME') or cfg.get('function_name')
353354
)
354355
print('Creating lambda function with name: {}'.format(func_name))
355-
client.create_function(
356-
FunctionName=func_name,
357-
Runtime=cfg.get('runtime', 'python2.7'),
358-
Role=role,
359-
Handler=cfg.get('handler'),
360-
Code={'ZipFile': byte_stream},
361-
Description=cfg.get('description'),
362-
Timeout=cfg.get('timeout', 15),
363-
MemorySize=cfg.get('memory_size', 512),
364-
Environment={
365-
'Variables': {
366-
key.strip('LAMBDA_'): value
367-
for key, value in os.environ.items()
368-
if key.startswith('LAMBDA_')
356+
kwargs={
357+
'FunctionName': func_name,
358+
'Runtime': cfg.get('runtime', 'python2.7'),
359+
'Role': role,
360+
'Handler': cfg.get('handler'),
361+
'Code': {'ZipFile': byte_stream},
362+
'Description': cfg.get('description'),
363+
'Timeout': cfg.get('timeout', 15),
364+
'MemorySize': cfg.get('memory_size', 512),
365+
'Publish': True
366+
}
367+
368+
if cfg.get('environment_variables', None) is not None:
369+
kwargs.update(
370+
Environment = {
371+
'Variables': {
372+
key: value
373+
for key, value
374+
in cfg.get('environment_variables').items()
375+
}
369376
}
370-
},
371-
Publish=True
372-
)
377+
)
373378

379+
client.create_function( **kwargs )
374380

375381
def update_function(cfg, path_to_zip_file):
376382
"""Updates the code of an existing Lambda function"""

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
boto3==1.4.1
2-
botocore==1.4.61
1+
boto3==1.4.4
2+
botocore==1.5.62
33
click==6.6
44
docutils==0.12
55
futures==3.0.5

0 commit comments

Comments
 (0)