clients: cbc_proxy client has canary method

The CBC Proxy is essentially a lambda function which we invoke with
various arguments.

A way in which this can fail is that the notifications-api app invoking
the function may not be able, any longer, to invoke the function.

This could be caused by, for example:
* an egress restriction preventing access to eu-west-2.lambda.amazonaws.com
* a network partition preventing access to eu-west-2.lambda.amazonaws.com
* the app's credentials have been rotated or revoked

If we invoke a simple "canary" lambda function for which the app should
have access to invoke, and check it for failures, we will know quickly
if something is likely to be broken.

This is especially important for cell broadcasts compared to email/SMS
because we always have a baseline of traffic for email/SMS, and so any
failure is observed almost immediately. This is not true for CB where we
may expect to only see one CB message every week/month/quarter/year, as
opposed to every minute or second for email/SMS.

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
Co-authored-by: Pea <pea.tyczynska@digital.cabinet-office.gov.uk>
This commit is contained in:
Toby Lorne
2020-10-26 17:14:08 +00:00
parent fbf3b96113
commit 052de84c9e
2 changed files with 112 additions and 0 deletions

View File

@@ -26,6 +26,12 @@ class CBCProxyNoopClient:
def init_app(self, app):
pass
def send_canary(
self,
identifier,
):
pass
def create_and_send_broadcast(
self,
identifier, headline, description, areas
@@ -57,6 +63,26 @@ class CBCProxyClient:
aws_secret_access_key=app.config['CBC_PROXY_AWS_SECRET_ACCESS_KEY'],
)
def send_canary(
self,
identifier,
):
payload_bytes = bytes(json.dumps({
'identifier': identifier,
}), encoding='utf8')
result = self._lambda_client.invoke(
FunctionName='canary',
InvocationType='RequestResponse',
Payload=payload_bytes,
)
if result['StatusCode'] > 299:
raise Exception('Could not invoke lambda')
if 'FunctionError' in result:
raise Exception('Function exited with unhandled exception')
def create_and_send_broadcast(
self,
identifier, headline, description, areas,