Skip to content

Commit 81300c1

Browse files
committed
Merging environment variable support into master
2 parents 9dbb7bf + 99c517d commit 81300c1

File tree

5 files changed

+84
-28
lines changed

5 files changed

+84
-28
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

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ 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+
environment_variables:
160+
env1: foo
161+
env2: baz
162+
163+
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.
164+
165+
154166
Development
155167
===========
156168

aws_lambda/aws_lambda.py

Lines changed: 45 additions & 26 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 'environment_variables' in cfg:
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"""
@@ -392,18 +398,31 @@ def update_function(cfg, path_to_zip_file):
392398
Publish=True
393399
)
394400

395-
client.update_function_configuration(
396-
FunctionName=cfg.get('function_name'),
397-
Role=role,
398-
Handler=cfg.get('handler'),
399-
Description=cfg.get('description'),
400-
Timeout=cfg.get('timeout', 15),
401-
MemorySize=cfg.get('memory_size', 512),
402-
VpcConfig={
401+
kwargs = {
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': {
403409
'SubnetIds': cfg.get('subnet_ids', []),
404410
'SecurityGroupIds': cfg.get('security_group_ids', [])
405411
}
406-
)
412+
}
413+
414+
if 'environment_variables' in cfg:
415+
kwargs.update(
416+
Environment={
417+
'Variables': {
418+
key: value
419+
for key, value
420+
in cfg.get('environment_variables').items()
421+
}
422+
}
423+
)
424+
425+
client.update_function_configuration(**kwargs)
407426

408427

409428
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)