Repository: localstack/localstack

Issue:
Lambda update_function_configuration() returns an empty dict
The update_function_configuration currently returns an empty dict no matter what but certain lambda libraries (ie, Zappa) require a realistic return value... which is simply the current config after being updated.

https://github.com/localstack/localstack/blob/9cba1010dfcbf2b7672df4d7da46b7e8ab287f64/localstack/services/awslambda/lambda_api.py#L872

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda.html#Lambda.Client.update_function_configuration

There might also be some other magic enriching that result but my quick read-through looks like it's an empty dict.



<!-- Love localstack? Please consider supporting our collective:
👉  https://opencollective.com/localstack/donate -->


Discussion:

Resolving patch:
diff --git a/localstack/services/awslambda/lambda_api.py b/localstack/services/awslambda/lambda_api.py
--- a/localstack/services/awslambda/lambda_api.py
+++ b/localstack/services/awslambda/lambda_api.py
@@ -670,7 +670,10 @@ def get_lambda_policy(function):
         doc = doc if isinstance(doc, dict) else json.loads(doc)
         if not isinstance(doc['Statement'], list):
             doc['Statement'] = [doc['Statement']]
+        for stmt in doc['Statement']:
+            stmt['Principal'] = stmt.get('Principal') or {'AWS': TEST_AWS_ACCOUNT_ID}
         doc['PolicyArn'] = p['Arn']
+        doc['Id'] = 'default'
         docs.append(doc)
     policy = [d for d in docs if d['Statement'][0]['Resource'] == func_arn(function)]
     return (policy or [None])[0]
@@ -894,8 +897,7 @@ def update_function_configuration(function):
         lambda_details.envvars = env_vars
     if data.get('Timeout'):
         lambda_details.timeout = data['Timeout']
-    result = {}
-    return jsonify(result)
+    return jsonify(data)
 
 
 @app.route('%s/functions/<function>/policy' % PATH_ROOT, methods=['POST'])
@@ -943,7 +945,7 @@ def get_policy(function):
     policy = get_lambda_policy(function)
     if not policy:
         return jsonify({}), 404
-    return jsonify({'Policy': policy})
+    return jsonify({'Policy': json.dumps(policy), 'RevisionId': 'test1234'})
 
 
 @app.route('%s/functions/<function>/invocations' % PATH_ROOT, methods=['POST'])


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
@@ -3,6 +3,7 @@
 import json
 import time
 import unittest
+import six
 from io import BytesIO
 from localstack import config
 from localstack.constants import LOCALSTACK_ROOT_FOLDER, LOCALSTACK_MAVEN_VERSION
@@ -117,6 +118,8 @@ def test_add_lambda_permission(self):
         self.assertIn('Statement', resp)
         # fetch lambda policy
         policy = lambda_client.get_policy(FunctionName=TEST_LAMBDA_NAME_PY)['Policy']
+        self.assertIsInstance(policy, six.string_types)
+        policy = json.loads(to_str(policy))
         self.assertEqual(policy['Statement'][0]['Action'], action)
         self.assertEqual(policy['Statement'][0]['Resource'], lambda_api.func_arn(TEST_LAMBDA_NAME_PY))
         # fetch IAM policy