Repository: localstack/localstack

Issue:
Lambda Environment Variables
Is passing environment variables to Lamdas supported?  They don't seem to be showing up.  I am using LAMBDA_EXECUTOR=docker, not sure if that affects anything.  I have code that sets the environment variable that works natively on AWS though doesn't seem to work on localstack.  The environment variables are always empty.

    --environment Variables={S3_BUCKET=Test} \

```
aws lambda  create-function \
--region us-east-1 \
--function-name ReturnBucketName \
--zip-file fileb://file-path/Test_Environment_Variables.zip \
--role role-arn \
--environment Variables={S3_BUCKET=Test} \
--handler index.handler \
--runtime nodejs6.10 \
--version  version \
--profile default
```


Discussion:
+1. Also getting the same issue when using `update-function-configuration`

Edit: looks like the env vars get sent into the lambda function, but aren't shown in `list-functions `
Any fix for the issue?
+1
+1 
Is there any sort of workaround for this?  This is a pretty big issue for making lambdas work.

Resolving patch:
diff --git a/localstack/utils/cloudformation/template_deployer.py b/localstack/utils/cloudformation/template_deployer.py
--- a/localstack/utils/cloudformation/template_deployer.py
+++ b/localstack/utils/cloudformation/template_deployer.py
@@ -628,10 +628,13 @@ def deploy_resource(resource_id, resources, stack_name):
     LOG.debug('Deploying resource type "%s" id "%s"' % (resource_type, resource_id))
     func_details = func_details[ACTION_CREATE]
     func_details = func_details if isinstance(func_details, list) else [func_details]
+    results = []
     for func in func_details:
         client = get_client(resource, func)
         if client:
-            deploy_resource_via_sdk_function(resource_id, resources, resource_type, func, stack_name)
+            result = deploy_resource_via_sdk_function(resource_id, resources, resource_type, func, stack_name)
+            results.append(result)
+    return (results or [None])[0]
 
 
 def deploy_resource_via_sdk_function(resource_id, resources, resource_type, func_details, stack_name):
@@ -692,8 +695,8 @@ def deploy_resource_via_sdk_function(resource_id, resources, resource_type, func
 
     # invoke function
     try:
-        LOG.debug('Request for creating resource type "%s": %s %s' % (
-            resource_type, func_details['function'], params))
+        LOG.debug('Request for creating resource type "%s" in region %s: %s %s' % (
+            resource_type, aws_stack.get_region(), func_details['function'], params))
         result = function(**params)
     except Exception as e:
         LOG.warning('Error calling %s with params: %s for resource: %s' % (function, params, resource))


Test patch:
diff --git a/tests/integration/test_lambda.py b/tests/integration/test_lambda.py
--- a/tests/integration/test_lambda.py
+++ b/tests/integration/test_lambda.py
@@ -162,24 +162,25 @@ def test_invocation_type_dry_run(self):
         self.assertEqual(result['StatusCode'], 204)
 
     def test_lambda_environment(self):
+        vars = {'Hello': 'World'}
         zip_file = testutil.create_lambda_archive(
-            load_file(TEST_LAMBDA_ENV),
-            get_content=True,
-            libs=TEST_LAMBDA_LIBS,
-            runtime=LAMBDA_RUNTIME_PYTHON27
-        )
+            load_file(TEST_LAMBDA_ENV), get_content=True,
+            libs=TEST_LAMBDA_LIBS, runtime=LAMBDA_RUNTIME_PYTHON27)
         testutil.create_lambda_function(
-            func_name=TEST_LAMBDA_NAME_ENV,
-            zip_file=zip_file,
-            runtime=LAMBDA_RUNTIME_PYTHON27,
-            envvars={'Hello': 'World'}
-        )
+            func_name=TEST_LAMBDA_NAME_ENV, zip_file=zip_file,
+            runtime=LAMBDA_RUNTIME_PYTHON27, envvars=vars)
+
+        # invoke function and assert result contains env vars
         result = self.lambda_client.invoke(
             FunctionName=TEST_LAMBDA_NAME_ENV, Payload=b'{}')
         result_data = result['Payload']
-
         self.assertEqual(result['StatusCode'], 200)
-        self.assertDictEqual(json.load(result_data), {'Hello': 'World'})
+        self.assertDictEqual(json.load(result_data), vars)
+
+        # get function config and assert result contains env vars
+        result = self.lambda_client.get_function_configuration(
+            FunctionName=TEST_LAMBDA_NAME_ENV)
+        self.assertEqual(result['Environment'], {'Variables': vars})
 
         # clean up
         testutil.delete_lambda_function(TEST_LAMBDA_NAME_ENV)