Browse Source

Added ability to enable/disable notifications via an environment variable.

Fred Damstra 6 năm trước cách đây
mục cha
commit
cbd5e5ab9a
2 tập tin đã thay đổi với 8 bổ sung3 xóa
  1. 6 3
      README.md
  2. 2 0
      sns_error_notification.py

+ 6 - 3
README.md

@@ -48,9 +48,12 @@ second.
 1. Configure an SNS topic.
 2. Subscribe to the SNS topic using your email address.
 3. Grant your lanbda function `sns:Publish` permission.
-4. Set the environment variable `sns_error_topic` to your SNS topic's arn.
-5. Add `from sns_error_notification import sns_error_notification` to your handler.
-6. Add the line `@sns_error_notification` directly before your handler function.
+4. Set the environment variable `sns_error_topic` to your SNS topic's arn. 
+5. (Optional) Add the environment variable `sns_notifications_enabled` and set
+   to either the string `true` or `false` to quickly enable or disable email
+   notifications without code changes.
+6. Add `from sns_error_notification import sns_error_notification` to your handler.
+7. Add the line `@sns_error_notification` directly before your handler function.
 
 See the example.py for an example.
 

+ 2 - 0
sns_error_notification.py

@@ -27,6 +27,8 @@ import traceback
 
 def sns_error_notification(function_name):
     def wrapper(event, context):
+        if os.environ.get('sns_notifications_enabled', 'true') == 'false':
+            return function_name(event, context)
         try:
             sns_arn = os.environ.get('sns_error_topic',
               'Please set an environment variable "sns_error" topic')