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.'}))
def _log_disable_account_sending_request(self): ''' Log the disable account sending request. ''' self.logger.debug('Preparing to disable SES account sending...') self.logger.info( json_dump_request_event(class_name=self.__class__.__name__, method_name='disable_account_sending_request'))
def _log_get_ses_account_reputation_metrics_request(self, params): ''' Log the params used to get SES account reputation metrics. Args: params (dict): MetricDataQueries dict object. ''' self.logger.debug('Requesting SES reputation metric data for account') self.logger.info( json_dump_request_event( class_name=self.__class__.__name__, method_name='get_ses_account_reputation_metrics', params=params))
def _log_post_json_request(self, url, payload): ''' Logs JSON POST params. Args: url (str): The url being posted to. payload (dict): Dict containing the POST params. ''' self.logger.debug('Sending POST outbound request to %s', url) self.logger.info( json_dump_request_event(class_name=self.__class__.__name__, method_name='post_json', params=payload, details={'url': url}))
def _log_handle_ses_reputation_request(self, metrics, status): ''' Log the SES account reputation handler request. ''' critical_count = len(metrics.critical) warning_count = len(metrics.warning) ok_count = len(metrics.ok) self.logger.debug( 'SES account reputation metrics - critical: %s, warning: %s, ok: %s, status is %s!', critical_count, warning_count, ok_count, status) self.logger.info( json_dump_request_event(class_name=self.__class__.__name__, method_name='handle_ses_reputation', details={ 'critical': metrics.critical, 'warning': metrics.warning, 'ok': metrics.ok }))
def _log_handle_ses_quota_request(self, utilization_percent, threshold_percent, status): ''' Log the SES account quota handler request. Args: utilization_percent (float/int): Utilization percentage. 80% is 80. threshold_percent (float/int): Threshold percentage. 80% is 80. status (str): The status of the SES account quota. Ex: CRITICAL, WARNING, OK. ''' self.logger.debug( 'SES account sending percentage is at %s, threshold is at %s, status is %s!', utilization_percent, threshold_percent, status) self.logger.info( json_dump_request_event(class_name=self.__class__.__name__, method_name='handle_ses_quota', details={ 'utilization_percent': utilization_percent, 'threshold_percent': threshold_percent, 'status': status }))