浏览代码

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

Fred Damstra 6 年之前
父节点
当前提交
cbd5e5ab9a
共有 2 个文件被更改,包括 8 次插入3 次删除
  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.
 1. Configure an SNS topic.
 2. Subscribe to the SNS topic using your email address.
 2. Subscribe to the SNS topic using your email address.
 3. Grant your lanbda function `sns:Publish` permission.
 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.
 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 sns_error_notification(function_name):
     def wrapper(event, context):
     def wrapper(event, context):
+        if os.environ.get('sns_notifications_enabled', 'true') == 'false':
+            return function_name(event, context)
         try:
         try:
             sns_arn = os.environ.get('sns_error_topic',
             sns_arn = os.environ.get('sns_error_topic',
               'Please set an environment variable "sns_error" topic')            
               'Please set an environment variable "sns_error" topic')