Lambda - Only return Logs if LogType=Tail

This commit is contained in:
Bert Blommers 2020-05-07 10:55:15 +01:00
parent be5b1c592f
commit f82e834225
3 changed files with 16 additions and 3 deletions

View File

@ -1049,9 +1049,9 @@ class LambdaBackend(BaseBackend):
if fn:
payload = fn.invoke(body, headers, response_headers)
response_headers["Content-Length"] = str(len(payload))
return response_headers, payload
return payload
else:
return response_headers, None
return None
def do_validate_s3():

View File

@ -178,7 +178,7 @@ class LambdaResponse(BaseResponse):
function_name = unquote(self.path.rsplit("/", 2)[-2])
qualifier = self._get_param("qualifier")
response_header, payload = self.lambda_backend.invoke(
payload = self.lambda_backend.invoke(
function_name, qualifier, self.body, self.headers, response_headers
)
if payload:
@ -187,6 +187,8 @@ 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":
del response_headers["x-amz-log-result"]
status_code = 200
return status_code, response_headers, payload
else:

View File

@ -113,6 +113,7 @@ def test_invoke_requestresponse_function():
FunctionName="testFunction",
InvocationType="RequestResponse",
Payload=json.dumps(in_data),
LogType="Tail"
)
success_result["StatusCode"].should.equal(200)
@ -125,6 +126,16 @@ def test_invoke_requestresponse_function():
payload = success_result["Payload"].read().decode("utf-8")
json.loads(payload).should.equal(in_data)
# Logs should not be returned by default, only when the LogType-param is supplied
success_result = conn.invoke(
FunctionName="testFunction",
InvocationType="RequestResponse",
Payload=json.dumps(in_data),
)
success_result["StatusCode"].should.equal(200)
assert "LogResult" not in success_result
@mock_lambda
def test_invoke_requestresponse_function_with_arn():