Skip to content

Commit

Permalink
Merge pull request #10 from joseph-holland/Issue#9
Browse files Browse the repository at this point in the history
Issue #9 - Added notification functionality via SNS for both success …
  • Loading branch information
joseph-holland committed Aug 13, 2017
2 parents 509d741 + 6a9a58c commit 19937cb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def envvar_to_list(envvar):
return os.environ[envvar].split(',')


def send_notification(sns_arn, region, error):
def send_notification(sns_arn, region, subject, message):
client = boto3.client('sns')

response = client.publish(
TopicArn=sns_arn,
Message='Error running Lambda Graffiti Monkey in ' + region + '. Error Message: ' + error

Subject=subject,
Message=message
)

log.info('SNS Response: {}'.format(response))
Expand All @@ -60,14 +60,16 @@ def handler(event, context):
}
gm.initialize_monkey()
gm.start_tags_propagation()
send_notification(sns_arn, region, 'Graffiti Monkey completed successfully',
'Graffiti Monkey completed successfully in ' + region + '.')
return 'Graffiti Monkey completed successfully!'
except KeyError, e:
error_message = 'Error: Environment variable not set: ' + str(e)
log.error(error_message)
log.info('Sending SNS message to ' + sns_arn)
send_notification(sns_arn, region, error_message)
send_notification(sns_arn, region, 'Error running Graffiti Monkey',
'Error running Lambda Graffiti Monkey in ' + region + '. Error Message: ' + error_message)
except Exception, e:
error_message = 'Error: Graffiti Monkey encountered the following error: ' + str(e)
log.error(error_message)
log.info('Sending SNS message to ' + sns_arn)
send_notification(sns_arn, region, error_message)
send_notification(sns_arn, region, 'Error running Graffiti Monkey',
'Error running Lambda Graffiti Monkey in ' + region + '. Error Message: ' + error_message)

0 comments on commit 19937cb

Please sign in to comment.