Repository: getmoto/moto

Issue:
AWS Lambda response defaults to application/json, not html
Assume a simple lambda echo hander like:

```python
def lambda_handler(event, context):
    return {"statusCode": 200, "body": event}
```

Lambda payload

```python
{'FunctionName': 'lambda_dev',
 'InvocationType': 'RequestResponse',
 'LogType': 'None',
 'Payload': b'{"i": 0}'}
```

Actual AWS Lambda response:

```python
{'ExecutedVersion': '$LATEST',
 'Payload': <StreamingBody at 0x7f8c7f7273c0 for ClientResponseContentProxy at 0x7f8c7f727370>,
 'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive',
                                      'content-length': '37',
                                      'content-type': 'application/json',
                                      'date': 'Mon, 07 Jun 2021 00:38:46 GMT',
                                      'x-amz-executed-version': '$LATEST',
                                      'x-amzn-remapped-content-length': '0',
                                      'x-amzn-requestid': 'xxx',
                                      'x-amzn-trace-id': 'xxx'},
                      'HTTPStatusCode': 200,
                      'RequestId': 'xxx',
                      'RetryAttempts': 0},
 'StatusCode': 200}
```

moto mock Lambda response:

```python
{'Payload': <StreamingBody at 0x7f01dc7c3f00 for ClientResponseContentProxy at 0x7f01dc7c3eb0>,
 'ResponseMetadata': {'HTTPHeaders': {'content-length': '46',
                                      'content-type': 'text/html; '
                                                      'charset=utf-8',
                                      'date': 'Mon, 07 Jun 2021 00:34:30 GMT',
                                      'server': 'Werkzeug/2.0.1 Python/3.7.10',
                                      'x-amz-crc32': '261964869',
                                      'x-amzn-requestid': 'QL5OOJC1YA25GMP6PE432U0HUP5BMZQBNVIJOHVKL6FZ8WDJM8JW'},
                      'HTTPStatusCode': 200,
                      'RequestId': 'QL5OOJC1YA25GMP6PE432U0HUP5BMZQBNVIJOHVKL6FZ8WDJM8JW',
                      'RetryAttempts': 0},
 'StatusCode': 200}
```

## versions

```
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"

$ docker --version
Docker version 20.10.7, build f0df350

$ python --version
Python 3.7.10

$ poetry show moto
name         : moto
version      : 1.3.16
description  : A library that allows your python tests to easily mock out the boto library

dependencies
 - aws-xray-sdk >=0.93,<0.96 || >0.96
 - boto >=2.36.0
 - boto3 >=1.9.201
 - botocore >=1.12.201
 - cfn-lint >=0.4.0
 - cryptography >=2.3.0
 - docker >=2.5.1
 - ecdsa <0.15
 - flask *
 - idna >=2.5,<3
 - Jinja2 >=2.10.1
 - jsondiff >=1.1.2
 - MarkupSafe <2.0
 - mock *
 - more-itertools *
 - python-dateutil >=2.1,<3.0.0
 - python-jose >=3.1.0,<4.0.0
 - pytz *
 - PyYAML >=5.1
 - requests >=2.5
 - responses >=0.9.0
 - six >1.9
 - sshpubkeys >=3.1.0
 - werkzeug *
 - xmltodict *
 - zipp *

```



Discussion:

Resolving patch:
diff --git a/moto/awslambda/responses.py b/moto/awslambda/responses.py
--- a/moto/awslambda/responses.py
+++ b/moto/awslambda/responses.py
@@ -209,6 +209,7 @@ def _invoke(self, request, full_url):
             function_name, qualifier, self.body, self.headers, response_headers
         )
         if payload:
+            response_headers["content-type"] = "application/json"
             if request.headers.get("X-Amz-Invocation-Type") == "Event":
                 status_code = 202
             elif request.headers.get("X-Amz-Invocation-Type") == "DryRun":


Test patch:
diff --git a/tests/test_awslambda/test_lambda.py b/tests/test_awslambda/test_lambda.py
--- a/tests/test_awslambda/test_lambda.py
+++ b/tests/test_awslambda/test_lambda.py
@@ -157,6 +157,9 @@ def test_invoke_requestresponse_function(invocation_type):
         assert False, success_result["Payload"].read().decode("utf-8")
 
     success_result["StatusCode"].should.equal(200)
+    success_result["ResponseMetadata"]["HTTPHeaders"]["content-type"].should.equal(
+        "application/json"
+    )
     logs = base64.b64decode(success_result["LogResult"]).decode("utf-8")
 
     logs.should.contain("START RequestId:")
@@ -172,6 +175,9 @@ def test_invoke_requestresponse_function(invocation_type):
     )
 
     success_result["StatusCode"].should.equal(200)
+    success_result["ResponseMetadata"]["HTTPHeaders"]["content-type"].should.equal(
+        "application/json"
+    )
     assert "LogResult" not in success_result