Skip to content

Commit 2bc7256

Browse files
committed
Merge branch 'master' of github.com:nficano/python-lambda
* 'master' of github.com:nficano/python-lambda: Update README.rst Issue: nficano#11, nficano#26 Environment vars documentation standardized release proc standardized release proc standardized release proc Issue: nficano#11, nficano#26 Env Vars Create LICENSE Editorconfig for compliant editors Issue: nficano#11, nficano#26 Environment Variables Issue: nficano#11, nficano#26 Environment variable support Issue: nficano#11, nficano#26 Environment variable support
2 parents 48f561f + 84ffeec commit 2bc7256

File tree

6 files changed

+86
-29
lines changed

6 files changed

+86
-29
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
# Unix-style newlines with a newline ending every file
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true
7+
8+
# Matches multiple files with brace expansion notation
9+
# Set default charset
10+
[*.{js,py}]
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
14+
# 4 space indentation
15+
[*.py]
16+
indent_style = space
17+
indent_size = 4
18+
19+
[*.rst]
20+
trim_trailing_whitespace = true

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ISC License
22

3-
Copyright (c) 2016, Nick Ficano
3+
Copyright (c) 2017, Nick Ficano
44

55
Permission to use, copy, modify, and/or distribute this software for any
66
purpose with or without fee is hereby granted, provided that the above

README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ Now try and run:
151151
https://<API endpoint URL>
152152
# 5.8580000000000005
153153
154+
Environment Variables
155+
=====================
156+
Lambda functions support environment variables. In order to set environment variables for your deployed code to use, you can configure them in ``config.yaml``
157+
158+
.. code:: yaml
159+
160+
environment_variables:
161+
env1: foo
162+
env2: baz
163+
164+
This would create environment variables in the lambda instance upon deploy. If your functions don't need environment variables, simply leave this section out of your config.
165+
166+
154167
Development
155168
===========
156169

aws_lambda/aws_lambda.py

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -354,29 +354,35 @@ def create_function(cfg, path_to_zip_file):
354354
client = get_client('lambda', aws_access_key_id, aws_secret_access_key,
355355
cfg.get('region'))
356356

357+
#Do we prefer development variable over config?
357358
func_name = (
358359
os.environ.get('LAMBDA_FUNCTION_NAME') or cfg.get('function_name')
359360
)
360361
print('Creating lambda function with name: {}'.format(func_name))
361-
client.create_function(
362-
FunctionName=func_name,
363-
Runtime=cfg.get('runtime', 'python2.7'),
364-
Role=role,
365-
Handler=cfg.get('handler'),
366-
Code={'ZipFile': byte_stream},
367-
Description=cfg.get('description'),
368-
Timeout=cfg.get('timeout', 15),
369-
MemorySize=cfg.get('memory_size', 512),
370-
Environment={
371-
'Variables': {
372-
key.strip('LAMBDA_'): value
373-
for key, value in os.environ.items()
374-
if key.startswith('LAMBDA_')
362+
kwargs={
363+
'FunctionName': func_name,
364+
'Runtime': cfg.get('runtime', 'python2.7'),
365+
'Role': role,
366+
'Handler': cfg.get('handler'),
367+
'Code': {'ZipFile': byte_stream},
368+
'Description': cfg.get('description'),
369+
'Timeout': cfg.get('timeout', 15),
370+
'MemorySize': cfg.get('memory_size', 512),
371+
'Publish': True
372+
}
373+
374+
if 'environment_variables' in cfg:
375+
kwargs.update(
376+
Environment = {
377+
'Variables': {
378+
key: value
379+
for key, value
380+
in cfg.get('environment_variables').items()
381+
}
375382
}
376-
},
377-
Publish=True
378-
)
383+
)
379384

385+
client.create_function( **kwargs )
380386

381387
def update_function(cfg, path_to_zip_file):
382388
"""Updates the code of an existing Lambda function"""
@@ -398,18 +404,31 @@ def update_function(cfg, path_to_zip_file):
398404
Publish=True
399405
)
400406

401-
client.update_function_configuration(
402-
FunctionName=cfg.get('function_name'),
403-
Role=role,
404-
Handler=cfg.get('handler'),
405-
Description=cfg.get('description'),
406-
Timeout=cfg.get('timeout', 15),
407-
MemorySize=cfg.get('memory_size', 512),
408-
VpcConfig={
407+
kwargs = {
408+
'FunctionName': cfg.get('function_name'),
409+
'Role': role,
410+
'Handler': cfg.get('handler'),
411+
'Description': cfg.get('description'),
412+
'Timeout': cfg.get('timeout', 15),
413+
'MemorySize': cfg.get('memory_size', 512),
414+
'VpcConfig': {
409415
'SubnetIds': cfg.get('subnet_ids', []),
410416
'SecurityGroupIds': cfg.get('security_group_ids', [])
411417
}
412-
)
418+
}
419+
420+
if 'environment_variables' in cfg:
421+
kwargs.update(
422+
Environment={
423+
'Variables': {
424+
key: value
425+
for key, value
426+
in cfg.get('environment_variables').items()
427+
}
428+
}
429+
)
430+
431+
client.update_function_configuration(**kwargs)
413432

414433

415434
def function_exists(cfg, function_name):

aws_lambda/project_templates/config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ aws_secret_access_key:
1313
# dist_directory: dist
1414
# timeout: 15
1515
# memory_size: 512
16+
#
17+
# Experimental Environment variables
18+
environment_variables:
19+
env_1: foo
20+
env_2: baz

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)