-
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.
Route SNS notifications through a Lambda function (#5246)
- Loading branch information
1 parent
7fb38a6
commit d37cdec
Showing
6 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
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 NotifyController(AppController): | ||
|
||
@cached_property | ||
def email(self): | ||
return AzulEmailNotificationService() | ||
|
||
def digest(self, event: chalice.app.SNSEvent) -> None: | ||
self.email.notify_group(subject=event.subject, body=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,26 @@ | ||
from azul import config, JSON | ||
from azul.deployment import aws | ||
|
||
|
||
class AzulEmailNotificationService: | ||
|
||
def notify_group(self, subject: str, body: str) -> None: | ||
aws.ses.send_email( | ||
Source=f'notify@{config.indexer_endpoint.host}', | ||
Destination={ | ||
'ToAddresses': [config.monitoring_email] | ||
}, | ||
Message=self._format_message(subject, body) | ||
) | ||
|
||
def _format_message(self, subject: str, body: str) -> JSON: | ||
return { | ||
'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
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