properly log the lambda response correctly

boto returns a `StreamingBody`[1] response rather than a json struct.
We're currently just logging things like "Error calling lambda
o2-1-proxy with function error <botocore.response.StreamingBody object
at 0x7f74cd6e02e8>" which is obviously less than ideal. Also make the
tests properly reflect this - annoyingly it appears like we can't use
moto to reliably test this interface as the moto `mock_lambda` decorator
needs you to be running inside a docker container??

[1] https://botocore.amazonaws.com/v1/documentation/api/latest/reference/response.html#botocore.response.StreamingBody
This commit is contained in:
Leo Hemsted
2021-02-18 11:51:38 +00:00
parent 126d810d5a
commit 90e82aff3e
2 changed files with 4 additions and 9 deletions

View File

@@ -147,7 +147,7 @@ class CBCProxyClientBase(ABC):
elif 'FunctionError' in result:
current_app.logger.info(
f"Error calling lambda {lambda_name} with function error { result['Payload'] }"
f"Error calling lambda {lambda_name} with function error { result['Payload'].read() }"
)
success = False

View File

@@ -1,3 +1,4 @@
from io import BytesIO
import json
import uuid
from collections import namedtuple
@@ -380,10 +381,7 @@ def test_cbc_proxy_will_failover_to_second_lambda_if_function_error(
{
'StatusCode': 200,
'FunctionError': 'Handled',
'Payload': {
"errorMessage": "",
"errorType": "CBCNewConnectionError"
}
'Payload': BytesIO(json.dumps({"errorMessage": "", "errorType": "CBCNewConnectionError"}).encode('utf-8')),
},
{
'StatusCode': 200
@@ -522,10 +520,7 @@ def test_cbc_proxy_create_and_send_tries_failover_lambda_on_function_error_and_r
ld_client_mock.invoke.return_value = {
'StatusCode': 200,
'FunctionError': 'something',
'Payload': {
'errorMessage': 'some message',
'errorType': 'SomeErrorType'
}
'Payload': BytesIO(json.dumps({"errorMessage": "some message", "errorType": "SomeErrorType"}).encode('utf-8')),
}
with pytest.raises(CBCProxyRetryableException) as e: