-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[R] Route SNS notifications through a Lambda function (#5246)
- Loading branch information
1 parent
e9ce6c9
commit d411ff3
Showing
11 changed files
with
176 additions
and
22 deletions.
There are no files selected for viewing
Binary file removed
BIN
-4.16 MB
...eels/runtime/cryptography-41.0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Binary file not shown.
Binary file added
BIN
+4.16 MB
...eels/runtime/cryptography-41.0.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import chalice.app | ||
|
||
from azul import ( | ||
cached_property, | ||
) | ||
from azul.chalice import ( | ||
AppController, | ||
) | ||
from azul.indexer.notify_service import ( | ||
AzulEmailNotificationService, | ||
) | ||
|
||
|
||
class NotificationController(AppController): | ||
|
||
@cached_property | ||
def service(self): | ||
return AzulEmailNotificationService() | ||
|
||
def notify_group(self, event: chalice.app.SNSEvent) -> None: | ||
self.service.notify_group(event.subject, event.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import json | ||
import logging | ||
|
||
from azul import ( | ||
JSON, | ||
config, | ||
) | ||
from azul.deployment import ( | ||
aws, | ||
) | ||
from azul.strings import ( | ||
trunc_ellipses, | ||
) | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class AzulEmailNotificationService: | ||
|
||
def notify_group(self, subject: str, message: str) -> None: | ||
log.info('Notifying group of event %r', trunc_ellipses(message, 256)) | ||
# Try to improve readability by adding indent | ||
try: | ||
body = json.loads(message) | ||
except json.decoder.JSONDecodeError: | ||
log.warning('Not a JSON serializable event, sending as received.') | ||
body = message | ||
else: | ||
body = json.dumps(body, indent=4) | ||
response = aws.ses.send_email( | ||
FromEmailAddress=' '.join([ | ||
'Azul', | ||
config.deployment_stage, | ||
'Monitoring', | ||
'<monitoring@' + config.api_lambda_domain('indexer') + '>' | ||
]), | ||
Destination={ | ||
'ToAddresses': [config.monitoring_email] | ||
}, | ||
Content=self._content(subject, body) | ||
) | ||
log.info('Sent notification %r', response['MessageId']) | ||
|
||
def _content(self, subject: str, body: str) -> JSON: | ||
return { | ||
'Simple': { | ||
'Subject': { | ||
'Data': subject | ||
}, | ||
'Body': { | ||
'Text': { | ||
'Data': body | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters