-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlambda_handler.py
55 lines (42 loc) · 1.71 KB
/
lambda_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
'''
AWS Lambda function handler.
'''
import logging
import boto3
from ses_account_monitor.config import (
LAMBDA_AWS_SESSION_CONFIG,
LOG_LEVEL)
from ses_account_monitor.monitor import Monitor
from ses_account_monitor.util import (
json_dump_request_event,
json_dump_response_event)
logger = logging.getLogger(__name__)
logger.setLevel(LOG_LEVEL)
session = boto3.Session(**LAMBDA_AWS_SESSION_CONFIG)
ses_client = session.client('ses')
cloudwatch_client = session.client('cloudwatch')
def lambda_handler(event, context):
'''
Args:
event (dict/list/str/int/float/NoneType): AWS event data.
context (LambdaContext): Lambda runtime information.
'''
logger.debug('Lambda event received.')
logger.info(json_dump_request_event(class_name='lambda_handler',
method_name='lambda_handler',
params=event,
details={
'message': 'Lambda event received.'}))
monitor = Monitor(ses_client=ses_client,
cloudwatch_client=cloudwatch_client,
logger=logger)
monitor.handle_ses_sending_quota()
monitor.handle_ses_reputation()
response = monitor.send_notifications(raise_on_errors=True)
logger.debug('Lambda event processed.')
logger.info(json_dump_response_event(class_name='lambda_handler',
method_name='lambda_handler',
response=response,
details={
'message': 'Lambda event processed.'}))