Skip to content

Commit

Permalink
#812 explicit timeout vetext forwarder lambda (#813)
Browse files Browse the repository at this point in the history
* added 6 second timeout to vetext http connection

* updated response to twilio to 200

* updated tests to check for status 200 instead of 400/500

* added logging around ssm data retrieval to help troubleshoot boto timeouts

* Update lambda_functions/vetext_incoming_forwarder_lambda/vetext_incoming_forwarder_lambda.py

* Update lambda_functions/vetext_incoming_forwarder_lambda/vetext_incoming_forwarder_lambda.py

* Update lambda_functions/vetext_incoming_forwarder_lambda/vetext_incoming_forwarder_lambda.py

Co-authored-by: Kyle MacMillan <16893311+k-macmillan@users.noreply.github.com>
  • Loading branch information
jakehova and k-macmillan authored Aug 24, 2022
1 parent 178a2d8 commit ade1047
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def vetext_incoming_forwarder_lambda_handler(event: dict, context: any):
logger.debug(event)
push_to_dead_letter_sqs(event, "vetext_incoming_forwarder_lambda_handler")

return create_twilio_response(400)
return create_twilio_response()

logger.info("Successfully processed event to event_bodies")
logger.debug(event_bodies)
Expand All @@ -61,10 +61,10 @@ def vetext_incoming_forwarder_lambda_handler(event: dict, context: any):
logger.exception(e)
push_to_dead_letter_sqs(event, "vetext_incoming_forwarder_lambda_handler")

return create_twilio_response(500)
return create_twilio_response()


def create_twilio_response(status_code):
def create_twilio_response(status_code: int = 200):
twiml_response = '<?xml version="1.0" encoding="UTF-8"?><Response></Response>'

response = {
Expand Down Expand Up @@ -143,11 +143,15 @@ def read_from_ssm(key: str) -> str:
try:
ssm_client = boto3.client('ssm')

logger.info("Generated ssm_client")

response = ssm_client.get_parameter(
Name=key,
WithDecryption=True
)

logger.info("received ssm parameter")

return response.get("Parameter", {}).get("Value", '')
except Exception as e:
logger.error("General Exception With Call to VeText")
Expand Down Expand Up @@ -206,7 +210,7 @@ def make_vetext_request(request_body):
connection = None

try:
connection = http.client.HTTPSConnection(domain, context=ssl._create_unverified_context())
connection = http.client.HTTPSConnection(domain, timeout=6, context=ssl._create_unverified_context())
logger.info("generated connection to VeText")

connection.request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_failed_sqs_invocation_call_throws_general_exception_goes_to_retry_sqs(m
mocker.patch(f'{LAMBDA_MODULE}.process_body_from_sqs_invocation', side_effect=Exception)
response = vetext_incoming_forwarder_lambda_handler(event, None)

assert response['statusCode'] == 500
assert response['statusCode'] == 200
sqs_mock.assert_not_called()

@pytest.mark.parametrize('event', [(albInvokedWithoutAddOn), (albInvokeWithAddOn)])
Expand All @@ -136,7 +136,7 @@ def test_failed_alb_invocation_call_throws_general_exception_goes_to_retry_sqs(m
mocker.patch(f'{LAMBDA_MODULE}.process_body_from_alb_invocation', side_effect=Exception)
response = vetext_incoming_forwarder_lambda_handler(event, None)

assert response['statusCode'] == 500
assert response['statusCode'] == 200
assert response['body'] == '<?xml version="1.0" encoding="UTF-8"?><Response></Response>'
sqs_mock.assert_not_called()

Expand Down Expand Up @@ -182,7 +182,7 @@ def test_unexpected_event_received(mocker, all_path_env_param_set):
event = {}
response = vetext_incoming_forwarder_lambda_handler(event, None)

assert response['statusCode'] == 400
assert response['statusCode'] == 200
assert response['body'] == '<?xml version="1.0" encoding="UTF-8"?><Response></Response>'
sqs_dead_letter_mock.assert_called_once()

Expand Down

0 comments on commit ade1047

Please sign in to comment.