diff --git a/moto/awslambda/responses.py b/moto/awslambda/responses.py index b00dc7138..c06eb7b69 100644 --- a/moto/awslambda/responses.py +++ b/moto/awslambda/responses.py @@ -269,7 +269,10 @@ class LambdaResponse(BaseResponse): elif request.headers.get("X-Amz-Invocation-Type") == "DryRun": status_code = 204 else: - if request.headers.get("X-Amz-Log-Type") != "Tail": + if ( + request.headers.get("X-Amz-Log-Type") != "Tail" + and "x-amz-log-result" in response_headers + ): del response_headers["x-amz-log-result"] status_code = 200 return status_code, response_headers, payload diff --git a/moto/awslambda_simple/models.py b/moto/awslambda_simple/models.py index b1446b13e..68b7e32aa 100644 --- a/moto/awslambda_simple/models.py +++ b/moto/awslambda_simple/models.py @@ -51,6 +51,8 @@ class LambdaSimpleBackend(BaseBackend): response_headers: Any, ) -> Optional[Union[str, bytes]]: + if body: + return str.encode(body) return b"Simple Lambda happy path OK" diff --git a/tests/test_awslambda_simple/test_lambda_simple.py b/tests/test_awslambda_simple/test_lambda_simple.py index 3d0dccfd2..e316b7890 100644 --- a/tests/test_awslambda_simple/test_lambda_simple.py +++ b/tests/test_awslambda_simple/test_lambda_simple.py @@ -1,3 +1,4 @@ +import json from unittest import SkipTest import boto3 @@ -15,6 +16,36 @@ if settings.TEST_SERVER_MODE: @mock_iam @mock_lambda_simple def test_run_function(): + # Setup + client = setup_lambda() + + # Execute + result = client.invoke( + FunctionName=FUNCTION_NAME, + LogType="Tail", + ) + + # Verify + assert result["StatusCode"] == 200 + assert result["Payload"].read().decode("utf-8") == "Simple Lambda happy path OK" + + +@mock_iam +@mock_lambda_simple +def test_run_function_no_log(): + # Setup + client = setup_lambda() + payload = {"results": "results"} + + # Execute + result = client.invoke(FunctionName=FUNCTION_NAME, Payload=json.dumps(payload)) + + # Verify + assert result["StatusCode"] == 200 + assert json.loads(result["Payload"].read().decode("utf-8")) == payload + + +def setup_lambda(): client = boto3.client("lambda", LAMBDA_REGION) zip_content = get_test_zip_file1() function_name = FUNCTION_NAME @@ -30,10 +61,4 @@ def test_run_function(): MemorySize=128, Publish=True, ) - - result = client.invoke( - FunctionName=FUNCTION_NAME, - LogType="Tail", - ) - assert result["StatusCode"] == 200 - assert result["Payload"].read().decode("utf-8") == "Simple Lambda happy path OK" + return client