Class: LambdaLoadout::ErrorNotifier
- Inherits:
-
Object
- Object
- LambdaLoadout::ErrorNotifier
- Defined in:
- lib/lambda_loadout/error_notifier.rb
Overview
ErrorNotifier sends detailed error notifications via SNS when Lambda functions fail
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#sns_topic_arn ⇒ Object
readonly
Returns the value of attribute sns_topic_arn.
Instance Method Summary collapse
-
#initialize(sns_topic_arn:, logger:, region: nil) ⇒ ErrorNotifier
constructor
Initialize ErrorNotifier.
-
#notify(error:, context:, event:) ⇒ void
Send error notification via SNS.
Constructor Details
#initialize(sns_topic_arn:, logger:, region: nil) ⇒ ErrorNotifier
Initialize ErrorNotifier
31 32 33 34 35 36 |
# File 'lib/lambda_loadout/error_notifier.rb', line 31 def initialize(sns_topic_arn:, logger:, region: nil) @sns_topic_arn = sns_topic_arn @logger = logger @region = region || ENV['AWS_REGION'] || 'us-east-1' @sns_client = nil # Lazy initialize end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
24 25 26 |
# File 'lib/lambda_loadout/error_notifier.rb', line 24 def logger @logger end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
24 25 26 |
# File 'lib/lambda_loadout/error_notifier.rb', line 24 def region @region end |
#sns_topic_arn ⇒ Object (readonly)
Returns the value of attribute sns_topic_arn.
24 25 26 |
# File 'lib/lambda_loadout/error_notifier.rb', line 24 def sns_topic_arn @sns_topic_arn end |
Instance Method Details
#notify(error:, context:, event:) ⇒ void
This method returns an undefined value.
Send error notification via SNS
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lambda_loadout/error_notifier.rb', line 44 def notify(error:, context:, event:) return if sns_topic_arn.nil? || sns_topic_arn.empty? begin ensure_sns_client subject = build_subject(error, context) = (error, context, event) @sns_client.publish( topic_arn: sns_topic_arn, subject: subject, message: ) logger.info('Error notification sent', topic_arn: sns_topic_arn, error_class: error.class.name) rescue StandardError => e # Don't let notification errors prevent the original error from being raised logger.warn('Failed to send error notification', e, topic_arn: sns_topic_arn, original_error: error.class.name) end end |