Lambda: fix no log response bug (#7038)
This commit is contained in:
parent
b54863523b
commit
a0876916b9
@ -269,7 +269,10 @@ class LambdaResponse(BaseResponse):
|
|||||||
elif request.headers.get("X-Amz-Invocation-Type") == "DryRun":
|
elif request.headers.get("X-Amz-Invocation-Type") == "DryRun":
|
||||||
status_code = 204
|
status_code = 204
|
||||||
else:
|
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"]
|
del response_headers["x-amz-log-result"]
|
||||||
status_code = 200
|
status_code = 200
|
||||||
return status_code, response_headers, payload
|
return status_code, response_headers, payload
|
||||||
|
@ -51,6 +51,8 @@ class LambdaSimpleBackend(BaseBackend):
|
|||||||
response_headers: Any,
|
response_headers: Any,
|
||||||
) -> Optional[Union[str, bytes]]:
|
) -> Optional[Union[str, bytes]]:
|
||||||
|
|
||||||
|
if body:
|
||||||
|
return str.encode(body)
|
||||||
return b"Simple Lambda happy path OK"
|
return b"Simple Lambda happy path OK"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
from unittest import SkipTest
|
from unittest import SkipTest
|
||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
@ -15,6 +16,36 @@ if settings.TEST_SERVER_MODE:
|
|||||||
@mock_iam
|
@mock_iam
|
||||||
@mock_lambda_simple
|
@mock_lambda_simple
|
||||||
def test_run_function():
|
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)
|
client = boto3.client("lambda", LAMBDA_REGION)
|
||||||
zip_content = get_test_zip_file1()
|
zip_content = get_test_zip_file1()
|
||||||
function_name = FUNCTION_NAME
|
function_name = FUNCTION_NAME
|
||||||
@ -30,10 +61,4 @@ def test_run_function():
|
|||||||
MemorySize=128,
|
MemorySize=128,
|
||||||
Publish=True,
|
Publish=True,
|
||||||
)
|
)
|
||||||
|
return client
|
||||||
result = client.invoke(
|
|
||||||
FunctionName=FUNCTION_NAME,
|
|
||||||
LogType="Tail",
|
|
||||||
)
|
|
||||||
assert result["StatusCode"] == 200
|
|
||||||
assert result["Payload"].read().decode("utf-8") == "Simple Lambda happy path OK"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user