From 4f7d6e15c967b0d250690dc63efda97f9c25d5f4 Mon Sep 17 00:00:00 2001 From: Jacob Grismo Date: Fri, 28 Dec 2018 22:16:07 -0500 Subject: [PATCH 1/2] adds failing test case for lambda cfm env vars Adds a failing test case that shows that a Lambda function resource in a CloudFormation template ignores the Environment variable mapping. --- .../test_cloudformation_stack_integration.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index 2c808726f..449fde4ce 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -1952,7 +1952,12 @@ def lambda_handler(event, context): "Description": "Test function", "MemorySize": 128, "Role": "test-role", - "Runtime": "python2.7" + "Runtime": "python2.7", + "Environment": { + "Variables": { + "TEST_ENV_KEY": "test-env-val", + } + }, } } } @@ -1973,6 +1978,9 @@ def lambda_handler(event, context): result['Functions'][0]['MemorySize'].should.equal(128) result['Functions'][0]['Role'].should.equal('test-role') result['Functions'][0]['Runtime'].should.equal('python2.7') + result['Functions'][0]['Environment'].should.equal({ + "Variables": {"TEST_ENV_KEY": "test-env-val"} + }) @mock_cloudformation From 7b008ded3e1be9966909d08c739ccb809d3ceb1b Mon Sep 17 00:00:00 2001 From: Jacob Grismo Date: Fri, 28 Dec 2018 23:05:25 -0500 Subject: [PATCH 2/2] adds Environment to the Lambda cfm optional keys Adds Environment to the list of keys that can be included in Lambda cloudformation functions. --- moto/awslambda/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moto/awslambda/models.py b/moto/awslambda/models.py index b11bde042..a37a15e27 100644 --- a/moto/awslambda/models.py +++ b/moto/awslambda/models.py @@ -386,7 +386,7 @@ class LambdaFunction(BaseModel): 'Role': properties['Role'], 'Runtime': properties['Runtime'], } - optional_properties = 'Description MemorySize Publish Timeout VpcConfig'.split() + optional_properties = 'Description MemorySize Publish Timeout VpcConfig Environment'.split() # NOTE: Not doing `properties.get(k, DEFAULT)` to avoid duplicating the # default logic for prop in optional_properties: